【发布时间】:2018-05-09 14:11:52
【问题描述】:
那是我的 xml
<?xml version = "1.0" encoding = "UTF-8"?>
<ns0:GetADSLProfileResponse xmlns:ns0 = "http://">
<ns0:Result>
<ns0:eCode>0</ns0:eCode>
<ns0:eDesc>Success</ns0:eDesc>
</ns0:Result>
</ns0:GetADSLProfileResponse>
这是我在java中的代码我需要知道如何开始 我在网上尝试了一些代码,但仍然没有解决我的问题 如何获取结果中的值以在其中循环并在 ecode 中获取 0 并在 eDesc 中获取 Success
CustomerProfileResult pojo = new CustomerProfileResult();
String body = readfile();
System.out.println(body);
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document dom = db.parse(new InputSource(new StringReader(body)));
XPath xpath =XPathFactory.newInstance().newXPath();
XPathExpression name = xpath.compile("/xml/GetADSLProfileResponse/Result");
NodeList nodeName = (NodeList) name.evaluate(dom, XPathConstants.NODESET);
if(nodeName!=null){
}
【问题讨论】:
-
你可以使用其他库吗?
-
任何链接将不胜感激,谢谢
-
我在 JacksonXML 方面拥有丰富的经验。如果您可以拉入该库,它将为您进行低级解析。 github.com/FasterXML/jackson-dataformat-xml