Jump to content

Getting Xml Values


Shakazahn

Recommended Posts

Hello,I was following w3 tutorial and while trying some examples I got to this:

document.getElementById('myBody').innerHTML = xmlDoc.getElementsByTagName('main')[0].childNodes[0].nodeValue;

...which works really fine, but I can't get anything else than that.From the tutorial: * xmlDoc - the XML DOM object created by the parser. * getElementsByTagName("title")[0] - the first <title> element * childNodes[0] - the first child of the <title> element (the text node) * nodeValue - the value of the node (the text itself)So I tried using childNodes[1] to get my 1st subelement (it's a section preview msg) but I couldn't get what was inside it. If I do .nodeName it calls the name correctly though, firstChild/lastChild works also, but I want to create multiple childs and access them through the parentName.Any help please?Edit: My XML file looks like this:

<main>  mainContent Here etc bla bla bla<mainPreview> this is the main section of the site </mainPreview></main>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...