Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.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
Java JIBX绑定松散的xml结构_Java_Xml_Data Binding_Unmarshalling_Jibx - Fatal编程技术网

Java JIBX绑定松散的xml结构

Java JIBX绑定松散的xml结构,java,xml,data-binding,unmarshalling,jibx,Java,Xml,Data Binding,Unmarshalling,Jibx,我正在使用org.jibx.runtime.impl.UnmarshallingContext.unmarshalDocumentjava.io.Reader rdr类来解组xml 这是我的绑定映射,可以工作 <?xml version="1.0" encoding="UTF-8"?> <binding xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <mapping name="md"

我正在使用org.jibx.runtime.impl.UnmarshallingContext.unmarshalDocumentjava.io.Reader rdr类来解组xml

这是我的绑定映射,可以工作

<?xml version="1.0" encoding="UTF-8"?>

  <binding xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <mapping name="md" class="com.mycompany.metadata.JiBXMetadata" ordered="false">
          <value name="alice" field="aliceStr" style="element" usage="optional"/>
          <value name="bob" field="bobStr" style="element" usage="optional"/>
          <value name="carol" field="carolStr" style="element" usage="optional"/>
      </mapping>
  </binding>
因此,如果xml中有任意顺序的节点alice、bob或carol,它都可以正常工作。如果xml中缺少任何节点,它仍然可以正常工作。但是如果xml中有一个额外的节点,比如steve,那么我会得到一个JiBXException


有没有办法让解组器忽略不在绑定映射中的任何节点?

添加灵活选项可能会有所帮助。您是否可以尝试将flexible属性添加到映射中,如下所示

<binding xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <mapping name="md" class="com.mycompany.metadata.JiBXMetadata" ordered="false">
      <value name="alice" field="aliceStr" style="element" usage="optional" flexible="true"/>
      <value name="bob" field="bobStr" style="element" usage="optional" flexible="true"/>
      <value name="carol" field="carolStr" style="element" usage="optional" flexible="true"/>
  </mapping>