XPath检查多个子节点文本

时间:2017-07-12 07:45:39

标签: xml xpath

我正在开展OVAL(开放漏洞和评估语言)。我正在使用xpath检查xml配置文件。

XML文件是这样的:

<?xml version='1.0' encoding='UTF-8'?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>listings</param-name>
            <param-value>false</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
</servlet>
</web>

我想检查内部init-param param-name必须包含debugparam-value也必须包含0

我正在写这样的xpath

<xpath datatype="string" operation="equals">/*[local-name()="web-app"]/*[local-name()="servlet"]/*[local-name()="init-param"]/*[local-name()="param-name"][text()="debug"][local-name()="param-value"][text()="0"]</xpath>

但它不是在催促,还有其他方法可以检查吗?

1 个答案:

答案 0 :(得分:0)

try this locator:

//init-param[./param-name[contains(text(),'debug')]][./param-value[contains(text(),'0')]]

logic is simple: locator to get element with special attribute looks like this: tag[attribute], you can get elements with multiple attributes using it too: tag[attribute1][attribute2] or tag[attribute1 and attribute2]