我們使用Jersey連接到第三方。然後,我們想要將返回的xml提取到我們的類中。這實際上工作正常,除了在子節點中的xml中的一個節點。 下面是返回的XML:使用Jersey分析子節點
<response>
...
<langISO>en</langISO>
<acquirerAmount>1000</acquirerAmount>
<acquirerCurrency>GBP</acquirerCurrency>
<subXml>
<authCode>122958</authCode>
</subXml>
</response>
注意,AUTHCODE節點是一個子節點(稱爲subXml)。
OurResponse myriadResponse = response.getEntity(OurResponse.class);
這裏是我們班的,但它不解析出AUTHCODE
package com.xxx;
import javax.ws.rs.Consumes;
import javax.ws.rs.Path;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
@Consumes("application/xml")
public class OurResponse {
private String authCode;
@XmlElement(name = "subXml/authCode")
public String getAuthCode() {
return authCode;
}
@XmlElement(name = "subXml/authCode")
public void setAuthCode(String authCode) {
this.authCode = authCode;
}
}
太棒了!謝謝!選項2正在工作。 – phil 2010-09-15 09:01:32
很高興我能幫到你。既然你是新手,一旦你找到你的答案,我們鼓勵你將其標記爲公認的答案。 – 2010-09-15 09:39:50