xsd具有相同名称的元素时出现Jaxb绑定错误

时间:2018-10-08 12:25:27

标签: xsd jaxb xjb

我有以下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 &lt;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 &lt;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。

0 个答案:

没有答案