Help with DOM, Small issue |
Help with DOM, Small issue |
Kay_Zee |
Oct 26 2009, 12:08 AM
Post
#1
|
Group: Members Posts: 1 Joined: 26-October 09 Member No.: 10,136 |
I've got my DOM working and reading/parsing an XML, but in my XML, certain nodes are repeated, eg.:
CODE <a> <b>Something</b> <c>Something <d>Info</d> <d>Info</d> </c> </a> I have a section of JavaScript set out to do this CODE case Node.ELEMENT_NODE: { String elementName = currnode.getNodeName(); if (elementName.equals("b")) out.println("<p><u>b: </u>"); if (elementName.equals("d")) out.print("<p>d: "); With this code, when it reaches certain parts of my XML it'll print: d: Info d: Info But I'd like it to be d: Info, Info. Is that possible? CODE case Node.TEXT_NODE: { String text = currnode.getNodeValue().trim(); String textName = currnode.getNodeName(); if (text.length() > 0) { out.println(text); } The above code prints the actual text. |
Christian J |
Oct 26 2009, 09:41 AM
Post
#2
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
QUOTE With this code, when it reaches certain parts of my XML it'll print: d: Info d: Info That's because each separate D element prints a new P element: CODE <p>d: QUOTE But I'd like it to be d: Info, Info. That looks like an array of the D elements' values. I'm not familiar with the kind of javascript you use above, with HTML most people seem to use foo.getElementsByTagName('d') to get an array (AKA "collection") of the D elements in the parent "foo". Then you can loop through that array, and print the child node value of each D element (if you are sure the child node of D is a text node) separated by e.g. commas. Here's a good DOM reference for HTML: http://www.quirksmode.org/dom/w3c_core.html |
Lo-Fi Version | Time is now: 26th April 2024 - 12:51 AM |