我有以下xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.1">
<xs:element name="ParentNode">
<xs:complexType>
<xs:sequence>
<xs:element name="References">
<xs:complexType>
<xs:sequence>
<xs:element name="Reference" maxOccurs="unbounded"
minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="Name" />
<xs:attribute type="xs:string" name="Value" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ChildNode1">
<xs:complexType>
<xs:sequence>
<xs:element name="References">
<xs:complexType>
<xs:sequence>
<xs:element name="Reference" maxOccurs="unbounded"
minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="Name" />
<xs:attribute type="xs:string" name="Value" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
以及以下xjb文件
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.1">
<bindings schemaLocation="parent.xsd" version="1.0">
<schemaBindings>
<package name="com.parent.xsdmodel"/>
</schemaBindings>
<bindings node="//xs:element[@name='Reference']">
<bindings node=".//xs:attribute[@name='Value']">
<property name="ValueAttribute"/>
</bindings>
</bindings>
</bindings>
我正在从命令行使用以下命令生成jaxb类:
xjc -p "com.parent.xsdmodel" -d "H:\git\parent\src\main\java" parent.xsd -b parent.xjb
运行命令时出现以下错误:
parsing a schema...
[ERROR] XPath evaluation of "//xs:element[@name='Reference']" results in too many (2) target nodes
line 11 of file:/H:/git/parent/src/main/resources/xsd/parent.xjb
[ERROR] Property "Value" is already defined. Use <jaxb:property> to resolve this conflict.
line 39 of jar:file:/C:/Program%20Files/Java/jdk1.8.0_162/lib/tools.jar!/com/sun/xml/internal/xsom/impl/parser/datatypes.xsd
[ERROR] The following location is relevant to the above error
line 35 of file:/H:/git/parent/src/main/resources/xsd/parent.xsd
[ERROR] Property "Value" is already defined. Use <jaxb:property> to resolve this conflict.
line 39 of jar:file:/C:/Program%20Files/Java/jdk1.8.0_162/lib/tools.jar!/com/sun/xml/interna l/xsom/impl/parser/datatypes.xsd
[ERROR] The following location is relevant to the above error
line 15 of file:/H:/git/parent/src/main/resources/xsd/parent.xsd
Failed to parse a schema.
有人可以建议在xsd文件中如何区分两个引用标记,即xjb文件中的ParentNode / References / Reference和ParentNode / ChildNode1 / References / Reference。