我正在尝试为每种类型的元素只创建一个适配器,所以我创建了一个bindings.xml文件:
<jxb:bindings node="//xs:attribute[@type='Id']"
所以,我的目的是解决“Id”类型的每个属性。 问题是xjc告诉我“太多目标节点(3)”......但这正是我想要的!!
答案 0 :(得分:32)
尝试添加multiple =“true”属性:
<jxb:bindings multiple="true" node="//xs:attribute[@type='Id']"
答案 1 :(得分:0)
我最终遇到了类似的问题&#34;目标节点太多(3)&#34;然而,在任何网站上找不到任何答案......发布我经过大量追踪和错误后发现的解决方案...解决的基本思路&#34;太多的目标节点(3)&#34;是给出XSD中多个节点的完整XPATH。
以下是我的XSD:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="document">
<xs:complexType>
<xs:sequence>
<xs:element name="asset">
<xs:complexType>
<xs:sequence>
<xs:element name="attribute" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="string" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="value" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="date" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="value" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="array" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="struct" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="field" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="integer" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:byte" name="value"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="assetreference" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="type"/>
<xs:attribute type="xs:long" name="value"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="name" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="integer" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:long" name="value"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="file" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="name" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="integer" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:short" name="value"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="name" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:long" name="id"/>
<xs:attribute type="xs:string" name="type"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
及以下是适用于上述XSD的JAXB绑定文件:
<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= "../assetproduct.xsd" version="1.0">
<!-- Customise the package name
<schemaBindings>
<package name="com.example.schema"/>
</schemaBindings> -->
<!-- rename the value element -->
<bindings node="//xs:element[@name='document']">
<bindings node="//xs:element[@name='asset']">
<bindings node="//xs:element[@name='attribute']">
<bindings node="//xs:element[@name='string']">
<bindings node=".//xs:attribute[@name='value']">
<property name="ValueAttribute"/>
</bindings>
</bindings>
<bindings node="//xs:element[@name='date']">
<bindings node=".//xs:attribute[@name='value']">
<property name="ValueAttribute"/>
</bindings>
</bindings>
<bindings node="//xs:element[@name='array']">
<bindings node=".//xs:element[@name='struct']">
<bindings node=".//xs:element[@name='field']">
<bindings node=".//xs:element[@name='integer']/xs:complexType">
<bindings node=".//xs:attribute[@name='value']">
<property name="ValueAttribute"/>
</bindings>
</bindings>
<bindings node=".//xs:element[@name='assetreference']">
<bindings node=".//xs:attribute[@name='value']">
<property name="ValueAttribute"/>
</bindings>
</bindings>
</bindings>
</bindings>
</bindings>
<bindings node=".//xs:element[@name='array']/xs:complexType/xs:sequence/xs:element[@name='integer']">
<bindings node=".//xs:attribute[@name='value']">
<property name="ValueAttribute"/>
</bindings>
</bindings>
<bindings node="//xs:element[@name='attribute']/xs:complexType/xs:sequence/xs:element[@name='integer']">
<bindings node=".//xs:attribute[@name='value']">
<property name="ValueAttribute"/>
</bindings>
</bindings>
</bindings>
</bindings>
</bindings>
</bindings>
</bindings>