• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

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.
 
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic