XML 节点
<!-- url path="/jsp/Admin_BetaSignup.jsp" roles="ZohoCampaignAdmin" authentication="optional" description="Page used to add the Beta users">
<param name="zuid" xss="throwerror" max-len="300"/>
</url -->
我想通过 xpath 选择这个节点。我在 java 中使用以下代码。
Document document = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse("/home/local/ZOHOCORP/bharathi-1397/build/AdventNet/Sas/webapps/zcadmin/WEB-INF/security.xml");
XPath xpath = XPathFactory.newInstance().newXPath();
System.out.println(
xpath.evaluate("//comment()[@path='/jsp/Admin_BetaSignup.jsp']",
document,XPathConstants.NODE)
);
输出:空。
为什么?
最佳答案
评论不是元素节点,它不包含属性。所以你必须获取所有评论节点,然后解析它们。
关于java - 我想根据属性值选择评论节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10633259/