0
在网上很好看,我正在努力与这一个。基本上,我调用一个API,它返回XML,这个XML需要更新,然后发送回api。我公司目前拥有的代码是:“[#document:null]”问题与XML解析
public string update(){
String url = GeneralProps.getProperty("XMLUpdateURL")+testCaseID+"/block/include/data/no";
ArrayList<String> tempArray = HttpHelper.sendAuthGetRequest(url, GeneralProps.getProperty("Username"), GeneralProps.getProperty("Password"));
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(tempArray.get(1).toString())));
XPathExpression expr = xpath.compile("//Step["+ stepNo + "]/"+ nodeName +"/text()");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
System.out.println(nodes.item(i).getNodeValue());
nodes.item(i).setNodeValue(newNodeValue);
System.out.println(nodes.item(i).getNodeValue());
}
return doc;
}
然而,DOC返回[#document:空] - 这意味着该文件实际上是在那里,我可以作出适当修改,但我似乎无法从文档获取XML因为这是需要绕过到另一种方法上传XML到API,但我无法弄清楚如何!