• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Reading Multi-layered XML

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to use Java and DOM parser. (Not that I know doing it in other language/with SAX, etc.)
I want to get the values of the attributes of the "group" node(?). ("Node" may not be the right nomenclature, please correct if it is not.)
Ex. For "B1" band, grpID attribute is "1" and numStdGrp attribute is "15".

Here is my XML file:




What I have done so far:



(1) numStudent and dataMain node is easy:
ex.

get node by nListDM.item(0), and use getNodeName() to display name

(2) band node can also be retrieved with getElementsByTagName.


I am stuck right after this.
How do I get attribute values of the node "group"?
getElementsByTagName(group) is probably bad idea: which band's group? Confusing.

Gurus, please give me some idea.

Thank you for taking time to read and possibly answer.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The standard library has methods for all the DOM manipulation methods you need - mostly in the org.w3c.dom package. Check out the nomenclature for the various kinds of Node in the javadocs for the org.w3c.dom.Node class - pay particular attention to the table in the Node documentation.

In your case "band" and "group" are Element nodes so getAttribute( ) will get the attribute value.

Bill
 
Tien Shan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
William Brogden:
Thank you for the tips. Yes, it worked!
Let me close this thread.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic