Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XPATH query - node exists? 1

Status
Not open for further replies.

russland

Programmer
Jan 9, 2003
315
CH
hi, i need to verify if a node with a specific value e.g. 'id' exists in my xml document? if i do this /employees/employee[id='4'], it would return nothing into my ixmlnode (visual basic). but i don't want to check for nothing ond that new node. how can i check? maybe something smart with length?

xml doc
<employees>
<employee><id>1</id><name>John Wayne</name></employee>
<employee><id>2</id><name>Max Payne</name></employee>
<employee><id>3</id><name>Jimy Hendrix</name></employee>
<employees>
 
I don't understand what you want: if you use a DomDocument, and you ask for a specific node and it returns nothing, then what more do you want?
 
You can use the count() function in your XPath. It will always return a node -- you just have to check if it's value is greater than 0.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
thanks to both of you. i preved the second solution/answer.

thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top