我有以下xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<include template="template.xml">
<param name="view" value="exampleValue"/>
<param name="table" value="exampleValue"/>
<param name="title" value="exampleValue"/>
<param name="addTitle" value="exampleValue"/>
<param name="permission" value="exampleValue"/>
<param name="icon" value="exampleValue"/>
</include> 现在,我想在我的xPath项目中检查<include>-node是否有一个名为template的属性,以及子节点是否包含一个name-attribute和相应的value。
我试过这个:
String expression ="//include[@template]"; //Expression;
NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
for (int i = 0; i < nodeList.getLength(); i++)
{
String match = nodeList.item(i).getAttributes().getNamedItem("value").toString();
String match2 = nodeList.item(i).getAttributes().getNamedItem("template").toString();
System.out.println(match);
System.out.println(match2);
}发布于 2015-07-03 06:35:17
试试这个/include[@template]/*[@name][@value]
这将给出包含元素/节点下包含名称和值的节点。
https://stackoverflow.com/questions/31199996
复制相似问题