gpt4 book ai didi

java - 如何创建绑定(bind)文件以将 complexType 更改为 simpleType

转载 作者:行者123 更新时间:2023-11-29 08:52:30 26 4
gpt4 key购买 nike

我在 XSD 架构中有一个字段:

<xs:element name="magicField">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:totalDigits value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

在java类中生成了一个字段:

int magicField;

但随后,xsd 架构已更改为:

<xs:element name="magicField">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="int_code">
<xs:totalDigits value="8"/>
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
</xs:element>

其中“int_code”:

<xs:complexType name="int_code">
<xs:simpleContent>
<xs:extension base="xs:positiveInteger">
<xs:attribute name="name"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

JAXB 生成以下代码:

MagicField magicField;

另外还有 MagicField.java。

但我还是需要

int magicField;

在生成的代码中。
根本不会使用属性“名称”。

我无法更改架构,我的方法只是绑定(bind)文件 (xjb)。

我应该如何创建绑定(bind)以重新映射“int_code”类型并将“magicField”获取为简单类型(代码中的int),而不是复杂类型(代码中的magicField) )?

据我所知,我还需要一个自定义的 XmlAdapter,而不仅仅是绑定(bind)规则。

提前致谢。

最佳答案

您可以使用以下内容而不是创建复杂类型 int_code:

<xs:element name="magicField">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="xs:positiveInteger">
<xs:totalDigits value="8"/>
</xs:restriction>
</xs:simpleContent>
</xs:complexType>

或者更好的方法是为 magicField 创建一个简单类型,如下所示:

   <xs:element name="magicField">
<xs:simpleType>
<xs:restriction base="xs:positiveInteger">
<xs:totalDigits value="8" />
</xs:restriction>
</xs:simpleType>
</xs:element>

希望这对您有所帮助。

关于java - 如何创建绑定(bind)文件以将 complexType 更改为 simpleType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22011875/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com