Jump to content

Getting Xml Values


Shakazahn
 Share

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>

Edited by Shakazahn
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
 Share

×
×
  • Create New...