• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XML Parsing Problem

 
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a javascript that calls the server and requests XML to be sent back. After the xml tag I have XML code such as this :
<ROOT>
<valDesc></valDesc>
<itmVal></itmVal>
<valDesc></valDesc>
<itmVal></itmVal>
...
</ROOT>
I want to capture the values returned and set them on my html page as name-value pairs for a select list. What's the easiest way to do this? I was trying to grab the ROOT tag and see how many children it had but it kept failing. Also how can I handle the XML content if the 2 repeating tags were combined such as <itmTag id="">value is</itmTag>? Thanks in advance for any help.
 
Ranch Hand
Posts: 58
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope you have gone through this

http://www.w3schools.com/Xml/xml_parser.asp

And for the second question you can get it by element.getAttribute('id') method.
 
Rob Hunter
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First off, I don't see anything in there that allows me to loop through the top level element (in this case ROOT). They show getElementsByTagName and I've tried doing that with ROOT but when I try and see what the length of childNodes[0] is I get an error childNodes.0 is null or not an object. I was wondering if I could do this or not.
Second, in the site you posted I didn't happen to notice where to extract attributes of a tag. I see a fair bit there for extracting nodeValue but how do I get at the attribute level? I'm using a XML Http Request and grabbing the content via XMLObj.responseXML.documentElement. Thanks for the response.
 
K West
Ranch Hand
Posts: 58
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You had to go through that website completely.

You can still go through this example..




Hope this helps..
 
Rob Hunter
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response K West. I found where the problem was. It was rather elementary but I'm new to playing to XML DOM so I don't feel as bad. I was trying to access the attribute such as XMLObj.childNodes[0].getAttribute(..). If I use getElementsByTagName I guess the childNodes in this case are really referencing the text nodes of the tags I've selected. I've read most of that site awhile back but without playing with it much I lost most of it through "memory leaks". That's why I'm playing with it now, to get more familar but the process. Thanks for the response, it's up and working now.
 
reply
    Bookmark Topic Watch Topic
  • New Topic