• Post Reply Bookmark Topic Watch Topic
  • New Topic

reading multple nested variables from XML  RSS feed

 
Ranch Foreman
Posts: 78
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an XML document that have multiple levels of nesting:

I need to return all the different values within each child element... ie.
Virtue: Innocence
Rank: 1
Physical Mitigation = 84
Physical Rating = 89
Tactical Mitigation = 29
Virtue: Innocence
Rank: 2
Physical Mitigation = 162
Physical Rating = 175
Tactical Mitigation = 54

I can read the XML okay but I get an error on displaying the information.



Any suggestions?
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Morgan wrote:Any suggestions?

Sure.

Tell us what exactly the error says.
 
John Morgan
Ranch Foreman
Posts: 78
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

java.lang.NullPointerException
at MyJavaCalc.ReadXMLFile.main(ReadXMLFile.java:47)

Line 47 is "System.out.println("Rank : " + eElement.getFirstChild().getAttributes().getNamedItem("ranklvl").getTextContent());"
 
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess would be that "eElement.getFirstChild()" is not what you think it is - it's probably a text node containing nothing but white space.

If the structure is always like you posted it, an approach using XPath might be easier. DOM is a pain in the neck to work with, IMO.

(As an aside, the first step to debugging this should have been to determine -and post- which part is null - eElement? getFirstChild() ? getAttributes() ? or getNamedItem("ranklvl")?)
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!