Jump to content

combine the checking of xml tags


zaheer

Recommended Posts

if i had the xml Doc<item><name></name><address>anwhere</address><tel>somenumber</tel></item><item><name>bob</name><tel>number</tel></item>i want to first check if the tag exists using this:var test = xmlDoc.getElementsByTagName("item").getElementsByTagName("name");if this test is successful, then i want to next check if the tag is empty. So i'd want something like this:if (test.length != 0 && // AND THE CODE FOR CHECKING FOR EMPTY ITEM)Does anyone know how to combine a check for both if a tag exists, and test if its empty.

Link to comment
Share on other sites

You may want to go through the XML DOM tutorial if you haven't already.http://www.w3schools.com/dom/dom_node.asp

// Because of the "i", I assume this is happening inside of a for loop...var test = xmlDoc.getElementsByTagName("item")[i].getElementsByTagName("name");if(test && test.length > 0){	// You can either loop through the "test" array or simply decide to use the first element.	// Using the first element...	if(test[0].nodeValue != "")	{	}}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...