2012-09-14 86 views
1

我解組像下面JAXB解組返回null

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <SOAP-ENV:Body> 
     <m:soResponse SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:m="urn:tec"> 
     <Error/> 
     <Order> 
      <Number>6</Number> 
     </Order> 
     </m:soResponse> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

SOAP消息的響應,並且即時結合JAXB註釋作爲

@XmlAccessorType(XmlAccessType.FIELD) 
    @XmlType(name = "", propOrder = { 
     "body" 
    }) 
    @XmlRootElement(name = "Envelope") 
    public class Envelope { 
    @XmlElement(name = "Body", namespace = "http://schemas.xmlsoap.org/soap/envelope/", required = true) 
     protected Body body; 
    //...... 
    } 

    @XmlAccessorType(XmlAccessType.FIELD) 
    @XmlType(name = "", propOrder = { 
     "soResponse" 
    }) 
    @XmlRootElement(name = "Body") 
    public class Body { 

     @XmlElement(namespace = "http://schemas.xmlsoap.org/soap/envelope/", required = true) 
     protected soResponse; 
    //----------- 
    } 
XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "", propOrder = { 
    "error", 
    "order" 
}) 
@XmlRootElement(name = "soResponse") 
public class soResponse{ 

    @XmlElement(name = "Error", required = true) 
    protected soResponse.Error error; 
    @XmlElement(name = "Order", required = true) 
    protected soResponse.Order order; 
    @XmlAttribute(name = "encodingStyle", namespace = "http://schemas.xmlsoap.org/soap/envelope/", required = true) 
    @XmlSchemaType(name = "anyURI") 
    protected String encodingStyle; 
//----------------------- 
} 

的問題是,我很得到soResponse總是空的!!?

+0

您究竟如何解組XML? 'soResponse'在你的例子中不是根元素(但是'Envelope')。簡單的解組不起作用。 – DRCB

+0

@DRCB在org.springframework.oxm.Unmarshaller –

回答

4

看起來你已經得到了錯誤的命名空間,你

@XmlElement(namespace = "http://schemas.xmlsoap.org/soap/envelope/", required = true) 
protected soResponse; 

這將尋找一個<SOAP-ENV:soResponse>,而不是一個<m:soResponse xmlns:m="urn:tec">

+0

中使用spring unmarshalling類,所以我應該在命名空間中寫入什麼? –

+0

與您的'soResponse'元素的名稱空間相匹配的URI,即''urn:tec「' –

+0

它正在工作,謝謝。 –