jaxb bindingx.xml “results in too many target nodes”

后端 未结 2 1699
感情败类
感情败类 2021-02-12 19:06

I\'m trying to make just one adapter for every type of element, so I created a bindings.xml file:

<         


        
相关标签:
2条回答
  • 2021-02-12 20:00

    Try to add multiple="true" attribute:

    <jxb:bindings multiple="true" node="//xs:attribute[@type='Id']"
    
    0 讨论(0)
  • 2021-02-12 20:01

    I end up with a similar problem "too many target nodes(3)" however could not find any answer on any of the sites...Posting the solution which I found after lots of trail and error...Basic idea to solve "too many target nodes(3)" is to give complete XPATH of the node which is multiple in your XSD.

    Below is my 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>
    

    and below is the JAXB binding file which is working for above XSD:

    <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>
    
    0 讨论(0)
提交回复
热议问题