xpath - Checking if attribute exits if only then select element -
my xpath works file when there attribute name test.
<a> <b test="added"> <c>test</c> </b> </a> xpath
//b[@test !='deleted']/c/text() but same xpath not work when there no attribute name test.
<a> <b> <c>test</c> </b> </a> xpath
//b[@test!='deleted']/c/text() what should make work if there no attribute name test.
try using not(@test ='deleted') instead :
//b[not(@test ='deleted')]/c/text() this xpath matches b elements test attribute doesn't equal 'deleted', including case when attribute test not present.
demo: xpathtester, xpatheval
xml:
<root> <a> <b test="added"> <c>test</c> </b> </a> <a> <b> <c>test</c> </b> </a> </root> output :
test test
Comments
Post a Comment