Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpath jaxb bindingx.xml“文件;导致目标节点过多“;_Xpath_Jaxb_Xsd - Fatal编程技术网

Xpath jaxb bindingx.xml“文件;导致目标节点过多“;

Xpath jaxb bindingx.xml“文件;导致目标节点过多“;,xpath,jaxb,xsd,Xpath,Jaxb,Xsd,我试图为每种类型的元素只制作一个适配器,因此我创建了bindings.xml文件: <jxb:bindings node="//xs:attribute[@type='Id']" 尝试添加multiple=“true”属性: <jxb:bindings multiple="true" node="//xs:attribute[@type='Id']" 我最终遇到了一个类似的问题“太多目标节点(3)”,但在任何站点上都找不到任何答案…发布了我在大量跟踪和错误后找到的解决方案…解决“

我试图为每种类型的元素只制作一个适配器,因此我创建了bindings.xml文件:

<jxb:bindings node="//xs:attribute[@type='Id']"
尝试添加multiple=“true”属性:

<jxb:bindings multiple="true" node="//xs:attribute[@type='Id']"

我最终遇到了一个类似的问题“太多目标节点(3)”,但在任何站点上都找不到任何答案…发布了我在大量跟踪和错误后找到的解决方案…解决“太多目标节点(3)”的基本思想是给出节点的完整XPATH,该节点在XSD中是多个的

下面是我的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>


遇到了相同的问题,并且
multiple=“true”
给出:无法执行此属性自定义。它附加到了错误的位置,或者与其他绑定不一致。我添加了
multiple=“true”
,但仍然收到错误消息“太多目标节点”。如果支持这么简单的话。。。为什么他们不允许多个节点作为默认值。。?Tnx的答案!