Jump to content

XML parser problem


Guest val

Recommended Posts

Hi friends!I want to load existing XML document in my browser like a HTML I using:<?xml version="1.0" encoding="ISO-8859-1"?><name> <first>Bobby</first> <middle>Bobson</middle> <last>Bobson</last> <role> - dude</role> <nickname> <first>Bob</first> <middle>Bo</middle> <last>B</last> </nickname></name>and the script<html><head><script type="text/javascript">var xmlDocfunction loadXML(){//load xml file// code for IEif (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load("note2.xml"); getmessage() }// code for Mozilla, etc.else if (document.implementation &&document.implementation.createDocument) { xmlDoc= document.implementation.createDocument("","",null); xmlDoc.load("note2.xml"); xmlDoc.onload=getmessage }else { alert('Your browser cannot handle this script'); }}function getmessage(){document.getElementById("first").innerHTML=xmlDoc.getElementsByTagName("first")[0].firstChild.nodeValuedocument.getElementById("middle").innerHTML=xmlDoc.getElementsByTagName("middle")[0].firstChild.nodeValuedocument.getElementById("last").innerHTML=xmlDoc.getElementsByTagName("last")[0].firstChild.nodeValuedocument.getElementById("role").innerHTML=xmlDoc.getElementsByTagName("role")[0].firstChild.nodeValuedocument.getElementById("nickname").innerHTML=xmlDoc.getElementsByTagName("nickname")[1].firstChild.nodeValuedocument.getElementById("first").innerHTML=xmlDoc.getElementsByTagName("first")[0].firstChild.nodeValue}</script></head><body onLoad="loadXML()" bgcolor="ffffff"><table border="0"><tr><td><span id="first"></span></td><td><span id="middle"></span></td><td><span id="last"></span></td><td><span id="role"></span></td><td><span id="nickname"></span></td><td><span id="first"></span></td></tr></table></body></html>My question is how to parse second element <nickname> <first>Bob</first> <middle>Bo</middle> <last>B</last> </nickname>because the tag names, coincide.THANKS.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...