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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking to see if a tag exists

Status
Not open for further replies.

rhull

Programmer
May 23, 2001
46
US
Is there a way to check to see if a tag exists using getElementsByTagName?

Something like

if objXMLDetails.getElementsByTagName("sentence") = FALSE

If I refer to a tag that doesn't exists I get an error,
problem is it may sometimes be used.

And the node order changes so

If objXMLDetails.childNodes(2).childNodes(3).nodeName = "sentence"
works but only if the tag is in that order.

Thanks
 
simple !
since getElementsByTagName returns a NodeList (i.e., an object) you can always equate it to null to see if the object really exists. Try this:
if(_obj.getElementsByTagName(tagName)==null)
...no such tag exists....
else
...such a tag exists....

regards
Madhu Tera

 
okay Im using ASP and when I use

If isNull(objXMLDetails.getElementsByTagName("charges") = False Then

else

...
But no matter what it seems to keep returning True,(or at least not null) so I am stumped.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top