XPATH expression to match context-param in web.xml
What will be xpath expression to match the context-param with param-name foo as shown below:
<web-app>
<context-param>
<param-name>foo</param-name>
<param-value>bar</param-value>
&l开发者_如何学编程t;description></description>
</context-param>
.....
</web-app>
/web-app/context-param[param-name/text() = 'foo']
//context-param[param-name='foo']
should do it. //context-param
asks for a list of all the nodes that is are descendants of the context node (i.e. the document root) with the name "context-param". The bit in square brackets then filters this list for context-param nodes which have a direct descendant with the name "param-name" and a text "foo". ='foo'
is shorthand for /text()='foo'
.
Also, watch out for namespaces in real use!
精彩评论