Quantcast
Channel: JavaScript - parse XML data - Stack Overflow
Viewing all articles
Browse latest Browse all 3

JavaScript - parse XML data

$
0
0

All of the other posts utilize parsing a simple XML and I need to see how to parse sub levels.

What others post...

<book><booktitle>something</booktitle><author>someone</author></book>

easy enough... but this is what I am dealing with and I need to start at cookbook...

<cookbook><bookid><booktitle>something</booktitle><author>someone</author></bookid><bookid><booktitle>something</booktitle><author>someone</author></bookid></cookbook>

In Powershell you can dig down by (book.bookid.booktitle) but I am not seeing this in Javascript. Another thing is that the id's , remain the same for each book but I need the name of each book.

var parser = new DOMParser();var xmlDoc = parser.parseFromString(book, "text/xml");var first = xmlDoc.getElementsByTagName("cookbook")[0].childNodes[0].nodeValue;

I need the cookbook>bookid>booktitle> for each book.I have tried setting the values for the node and child node but it never shows a returned value just blank or null. Again all the posts I have sen on here deal with one level not three deep and that is what is throwing me off.

This site had good info but again one level...https://developer.mozilla.org/en-US/docs/Web/Guide/Parsing_and_serializing_XML

Let me be clear on something. The xml I am parsing has the booktitle listed in other locations under other nested groups, say dogbook>bookid>booktitle. I want this group cookbook>bookid>booktitle> as the other titles are not wanted so searching for booktitle will return both cook and dog. Forgot that major important part duh...


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images