【发布时间】:2014-11-25 15:16:28
【问题描述】:
将 xml 文件解组为 java 类时,我得到了 null 值。但是 xml 文件作为值对应于它的属性。我的 pojo 类或解组中有任何错误吗? 请帮忙
这是我的宝珠
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
@XmlRootElement(name = "CardUpdateResponse",namespace="http://www.samople.com/Prepaid")
public class FVCardUpdateResponse {
@XmlElement(name = "AccountNumber")
private String AccountNumber;
@XmlElement(name = "ResCode")
private String ResCode;
@XmlElement(name = "ResErrorCode")
private String ResErrorCode;
@XmlElement(name = "ResErrorMsg")
private String ResErrorMsg;
//Setters and Getters
}
这是我的 xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<CardUpdateResponse xmlns="http://www.samople.com/Prepaid">
<CARDUPDATE_RET>
<ResErrorMsg>ID Issue Date must be equal or less than present date</ResErrorMsg>
<ResErrorCode>ErrIsud01</ResErrorCode>
<ResCode>0</ResCode>
<ACCOUNTNUMBER>2000000003918246</ACCOUNTNUMBER>
</CARDUPDATE_RET>
</CardUpdateResponse>
这是解组代码
public class XmlUnmarshelling {
public void unmarshell()
{
try
{
System.out.println("xml unmarshelling class");
File file = new File("D:/var/lib/tomcat7/webapps/tmpFiles/1.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(FVCardUpdateResponse.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
FVCardUpdateResponse CARDUPDATE_ret = (FVCardUpdateResponse) jaxbUnmarshaller.unmarshal(file);
System.out.println("xml unmarshelled = "+CARDUPDATE_ret.getResErrorMsg());//Getting null value as response.
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
【问题讨论】:
标签: java spring spring-mvc xml-parsing