dcsimg
How to determine if a tag exists in an XML document?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jason_Howard
Posted On:   Monday, March 3, 2003 08:42 AM

I have some code that parses an XML document and pulls out some selected elements. The problem I'm running into is that some of these XML documents have a tag that is named differently depending on the type of dataset the XML document references (called in one document, and in the next). My question is, how can I determine if one or the other tag exists in my XML document so I can send the correct one to a web page? Here's what I use now to extract my tag: node = document.getElementsByTagName("purpose").item(0); Thanks, Jason Howard Arizona State Cartographer's Office jhoward@lnd.state.az.us    More>>

I have some code that parses an XML document and pulls out some selected elements. The problem I'm running into is that some of these XML documents have a tag that is named differently depending on the type of dataset the XML document references (called in one document, and in the next).



My question is, how can I determine if one or the other tag exists in my XML document so I can send the correct one to a web page? Here's what I use now to extract my tag:



node = document.getElementsByTagName("purpose").item(0);


Thanks,



Jason Howard

Arizona State Cartographer's Office

jhoward@lnd.state.az.us
   <<Less

Re: How to determine if a tag exists in an XML document?

Posted By:   Roseanne_Zhang  
Posted On:   Monday, March 3, 2003 11:14 AM

That means you've already built the DOM tree, and it is very expensive.


A simple xpath will do the trick count(//tagname) = 0 means no such tagname, otherwise, yes.

About | Sitemap | Contact