1

I need to unmarshall XML.

XML is like this:

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

</array>

ok that's nice. now my java classes is like this:

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

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

    ...

}

and then:

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

public class Item{

    private Integer age;
    private String name;
    ...

now everything is just fine! unmarshalling goes well!

BUT what should I do when I have SOAP response like this?

<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>

How can I skip SOAP-ENV:Envelope , SOAP-ENV:Header, SOAP-ENV:Body,ns:ProviderResponse tags? Now, with this XML, when I'm trying to unmarshall I have such error:

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) 
grep
  • 4,615
  • 10
  • 48
  • 96
  • 1
    I've just solve the problem using StAX. I got the concrete XML and then I have created unmarshalling using JAX-B – grep Aug 27 '14 at 14:41

0 Answers0