每个人!我正在开发这个宁静的 Web 服务客户端,但我在尝试获取嵌套元素时遇到了问题。这是我收到的 XML。
<InstalledProducts>
<InstalledProduct>
<uri>
<url>
http://immix-test.natinst.com/ib-rest/1.0/installed-product/NIC:458513.xml
</url>
<urn>urn:installed-product:NIC:458513</urn>
</uri>
<instanceId>458513</instanceId>
<site>NIC</site>
<serialNumber>A49AD1</serialNumber>
<productNumber>459513</productNumber>
<ibStatus>Latest</ibStatus>
<ibCreationDate>1998-10-14</ibCreationDate>
<partNumber>
<urn>urn:product-item:181830E-01</urn>
</partNumber>
<latestServiceContracts>
<url>
http://immix-test.natinst.com/ib-rest/1.0/installed-product/NIC:458513/latestServiceContracts.xml
</url>
</latestServiceContracts>
<allServiceContracts>
<url>
http://immix-test.natinst.com/ib-rest/1.0/installed-product/NIC:458513/allServiceContracts.xml
</url>
</allServiceContracts>
</InstalledProduct>
</InstalledProducts>
这是处理 InstalledProduct RootElement 的 Java 类
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.log4j.Logger;
@XmlRootElement(name = "InstalledProduct")
public class InstalledProductDTO {
private ContractsURL latestServiceContracts;
private PartNumber partNumber;
public static Logger logger = Logger.getLogger(InstalledProductDTO.class);
private int instanceId;
private String status;
@XmlElement(name = "serviceStatus")
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
@XmlElement(name = "instanceId")
public int getInstanceId() {
return instanceId;
}
public void setInstanceId(int instanceId) {
this.instanceId = instanceId;
}
@XmlElement(name = "partNumber")
public PartNumber getpartNumberURN(){
return partNumber;
}
public void setProductNumber(PartNumber partNumber){
this.partNumber = partNumber;
}
@XmlElement(name = "latestServiceContracts")
public ContractsURL getLatestServiceContractsURL(){
return latestServiceContracts;
}
public void setAllServiceContractsURL(ContractsURL latestServiceContractsURL){
this.latestServiceContracts = latestServiceContractsURL;
}
}
这是处理 partNumber 标签的类,这就是问题所在。
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "partNumber")
public class PartNumber {
private String urn;
@XmlElement(name = "urn")
public String getURN()
{
return urn;
}
public void setUrn(String urn){
this.urn = urn;
}
}
当我尝试获取 partNumber 时,我得到一个空值。有任何想法吗?