我正在开展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
必须包含debug
而param-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>
但它不是在催促,还有其他方法可以检查吗?
答案 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]