JAXB - 覆盖元素的数据类型 [英] JAXB - Overriding datatype of an element
本文介绍了JAXB - 覆盖元素的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用带有以下自定义绑定的JAXB:
I am using JAXB with the following customized binding :
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" version="2.0" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:extensionBindingPrefixes="xjc" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxb:globalBindings typesafeEnumMaxMembers="2000">
<jaxb:serializable />
</jaxb:globalBindings>
<jaxb:bindings schemaLocation="test.xsd" node="/xs:schema//xs:complexType[@name='EN']//xs:element[@name='family']">
<jaxb:property>
<jaxb:baseType name="java.lang.String" />
</jaxb:property>
</jaxb:bindings>
</jaxb:bindings>
处理此架构(test.xsd):
to handle this schema (test.xsd):
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xsd:complexType name="EN" mixed="true">
<xsd:complexContent>
<xsd:extension base="ANY">
<xsd:sequence>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="family" type="en.family"/>
</xsd:choice>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="en.family" mixed="true">
<xsd:complexContent>
<xsd:restriction base="ENXP">
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ENXP" mixed="true">
<xsd:complexContent>
<xsd:extension base="ST">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ST" mixed="true">
<xsd:complexContent>
<xsd:restriction base="ED">
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ED" mixed="true">
<xsd:complexContent>
<xsd:extension base="BIN">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="BIN" abstract="true" mixed="true">
<xsd:complexContent>
<xsd:extension base="ANY">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ANY" abstract="true">
<xsd:attribute name="nullFlavor" type="xsd:string" use="optional">
</xsd:attribute>
</xsd:complexType>
</xsd:schema>
我遇到了这个问题:
[ERROR] compiler was unable to honor this property customization. It is attached to a wrong place, or its inconsistent with other bindings.
line 6 of file://home/user/test/jaxbelem_binding.xml
[ERROR] (the above customization is attached to the following location in the schema)
line 7 of file://home/user/test/test.xsd
Failed to parse a schema.
我的绑定文件有什么问题?
它关于 jaxb:property
,但当删除后者时,不会发生重写!
What's wrong with my binding file?
It's yaling about jaxb:property
, but when the latter is deleted, no overriding happens!
任何帮助将非常感谢,感谢提前大家!
Any help will be really appreciated, thanks in advance folks!
推荐答案
我已经幸运地嵌套了 jxb :绑定节点
标签内的 jxb:bindings schemaLocation
标签如下:
I have had luck nesting the jxb:bindings node
tag inside of the jxb:bindings schemaLocation
tag like this:
<?xml version="1.0" encoding="US-ASCII" ?>
<jxb:bindings version="2.0"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
>
<jxb:bindings schemaLocation="test.xsd">
<jxb:bindings node="//xs:element[@name='family']">
<jxb:property >
<jxb:baseType name="java.lang.String"></jxb:baseType>
</jxb:property>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
还:
- 当你的笔记xpath到'family'时,它似乎过于复杂。我将它更新为适用于你的示例xsd的一个(只要只有一个名为='family'的元素,它将起作用)
这篇关于JAXB - 覆盖元素的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文