cowsdonthack Posted July 6, 2010 Share Posted July 6, 2010 I'm working with an XML file, and I want to display all of it's properties using a format. I'm using "FOR"http://w3schools.com/ajax/ajax_xmlhttprequest_response.aspLike in this example, it pulls up the Artist and AlbumIt's dependant that the <Artist> and the <Album> tag is going to be there, but what if something goes missing?Then none of it works at all.The XML file I'm given has something like<EVENTS> <A> <B></B><C></C> </A> <A> <C></C> </A> <A> <B></B> </A></EVENTS>Using javascript, I have a script thatFor Each AShow B and CHow would I get it to show C if it exists, and B if it exists, without returning blank? Link to comment Share on other sites More sharing options...
ApocalypeX Posted July 20, 2010 Share Posted July 20, 2010 ...var txt=""; x=xmlDoc.getElementsByTagName("A"); for (i=0;i<x.length;i++) { b = x[i].getElementsByTagName("B"); c = x[i].getElementsByTagName("C"); if( B ){ txt += x[i].getElementsByTagName("B").childNodes[0].nodeValue; } if( C ){ txt += x[i].getElementsByTagName("C").childNodes[0].nodeValue; } } else{ }... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.