[英]How to create the binding file for changing complexType to simpleType
I had a field in XSD schema: 我在XSD模式中有一个字段:
<xs:element name="magicField">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:totalDigits value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
In java class was generated a field: 在java类中生成了一个字段:
int magicField;
But then, xsd schema has changed to: 但随后,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>
Where "int_code": 其中“ int_code”:
<xs:complexType name="int_code">
<xs:simpleContent>
<xs:extension base="xs:positiveInteger">
<xs:attribute name="name"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
And JAXB generates the following code: JAXB生成以下代码:
MagicField magicField;
and MagicField.java in additional. 和MagicField.java。
But I still need only 但是我仍然只需要
int magicField;
in generated code. 在生成的代码中。
Attribute "name" won't be used at all. 完全不使用属性“名称”。
I can't change the schema, my way is only binding file (xjb). 我无法更改架构,我的方式仅是绑定文件(xjb)。
How I should create the binding to re-map "int_code" type and get "magicField" as simpleType ( int
in code), not complexType ( magicField
in code)? 我应该如何创建绑定以重新映射“ int_code”类型并获得“ magicField”作为simpleType(代码中的
int
),而不是complexType(代码中的magicField
)?
As I understand I also need a custom XmlAdapter, not only binding rule. 据我了解,我不仅需要绑定规则,还需要自定义XmlAdapter。
Thanks in advance. 提前致谢。
You can use following instead of creating a complex type int_code: 您可以使用以下命令来代替创建复杂类型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>
Or a better way you can create a simpleType for magicField as below: 或者,您可以按照以下更好的方法为magicField创建simpleType:
<xs:element name="magicField">
<xs:simpleType>
<xs:restriction base="xs:positiveInteger">
<xs:totalDigits value="8" />
</xs:restriction>
</xs:simpleType>
</xs:element>
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.