Jak Balikai
Jak Balikai

Reputation: 81

How to check if node containing certain text exists in XML DOM?

My XML is as below:

enter image description here

I need to check whether "anil" is in the DOM or not without using loop. Is it possible to do this in one line?

This is the code I tried:

If not(xmldom.selectsinglenode("//xml/xmlfile/name/"+xname)is nothing) then
    .....
end if

Here xname will be the text (eg anil or amith).

Upvotes: 1

Views: 706

Answers (1)

har07
har07

Reputation: 89325

The correct XPath to get <name> element having inner text equals anil is as follow :

//xml/xmlfile/name[.='anil']

So the string parameter of selectsinglenode() should look about like this instead (or better yet using / instead of // at the beginning) :

"//xml/xmlfile/name[.='"+xname+"']"

Upvotes: 1

Related Questions