1

XML を非整列化する必要があります。

XML は次のようになります。

<array>
    <item>
          <name>nick</pid>
          <age>18</provider>
    </item>
    <item>
          <name>gogo</pid>
          <age>20</provider>
     </item>

</array>

いいですね。今、私のJavaクラスは次のようになっています:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "array")
public class Root{

    @XmlElement(name = "item", type = Provider.class)
    private List<Item> array = new ArrayList<Item>();

    ...

}

その後:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "item")

public class Item{

    private Integer age;
    private String name;
    ...

今、すべてがうまくいっています!アンマーシャリングはうまくいきます!

しかし、このようなSOAP 応答があった場合、どうすればよいでしょうか?

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns="http://example.com/ns.xsd" xmlns:impl="http://example.com/impl.xsd">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <ns:ProviderResponse>
         <Status>OK</Status>

           <array>
                ...
              <item>
                 ...
              </item>
                 ...
           </array>


      </ns:ProviderResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

SOAP-ENV:Envelope 、 SOAP-ENV:Header 、 SOAP-ENV:Body,ns:ProviderResponse タグをスキップするにはどうすればよいですか? さて、この XML でアンマーシャリングしようとすると、次のようなエラーが発生します。

javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Envelope"). Expected elements are <{}array>,<{}item>
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:647) 
4

0 に答える 0