我无法获得“var”节点的任何原因?我没有看到任何打印出来的东西。所以问题是节点什么都不返回。请帮忙。非常感谢!
这是我的java代码:
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(responseBody)));
XPath xpath = XPathFactory.newInstance().newXPath();
// XPath Query for showing all nodes value
XPathExpression expr = xpath.compile("/vxml/form/var");
NodeList nodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
System.out.println("test");
}
这是xml:
<?xml version="1.0" encoding="UTF-8"?>
<vxml xmlns="http://www.w3.org/2001/vxml" xmlns:voxeo="http://community.voxeo.com/xmlns/vxml" version="2.1">
<form id="XCONTENT">
<catch event="invalidResponse">
<assign name="responseRetries" expr="responseRetries+1" />
<clear namelist="CHOICES" />
<goto nextitem="CHOICES" />
</catch>
<var expr="1" name="responseRetries" />
<var expr="''" name="choice" />
<var expr="'8750000'" name="ntfnId" />
<var expr="'8749000,8748000,8747000,8746000'" name="notIds" />
<var expr="'228971'" name="deviceId" />
<var expr="'0'" name="nodeId" />
<var expr="'1'" name="orgId" />
<var expr="'English'" name="userPreferredLang" />
<var expr="'slow'" name="ttsRate" />
<var expr="false" name="isValidationMessage" />
<var expr="'8750000'" name="processedNotificationIds" />
<var expr="'1815f630-bda2-45be-b08b-46a51d3aebd4'" name="callSid" />
<var expr="'BEFORE'" name="authState" />
<var expr="''" name="authNotificationIds" />
<var expr="''" name="nodeName" />
<var expr="false" name="RESPONSE_PLAYED" />
<var expr="'true'" name="hasContent" />
</form>
</vxml>
答案 0 :(得分:0)
您的元素位于命名空间中,但您的XPath正在查找无命名空间中的元素。在此站点中搜索&#34; XPath默认命名空间&#34;找到成千上万遇到同样问题的人。