This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java xml reading dom metods help

 
simon did
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey i also asked this queston here ;)
http://www.java-forums.org/new-java/84292-java-xml-reading-dom-metods-help.html

hey so i have this giant xml document with a lot off data in
https://api.eveonline.com/eve/SkillTree.xml.aspx

I’m trying to load this xml document in to a sql database my problem is reading the document
i need to make every skill in to a different row in my db with columns like description,rank,requiredAttributes, requiredSkills, skillBonusCollection my problem is reading the required Skills and skillBonusCollection

so what i want to do is to make each row off skills
example :


Take this and get everything out as different variables

i already made it work with getting stuff like typename, typeid, description,rank out of the dukoment without errors but in having trouble when i need to acces requiredskills, requiredattributes,skillbonusCollection
be aware that required skills might not exist

Below is my currently code where some parts is working but accessing requiredskills, requiredattributes,skillbonusCollection isn’t

Java Code:

 
K. Tsang
Bartender
Posts: 3496
14
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a hasAttributes() method in the Node interface.

Then there is a class called Attr


 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
simon did wrote:Below is my currently code where some parts is working but accessing requiredskills, requiredattributes,skillbonusCollection isn’t

What problem are you having? Specifically what input, what output, what is the difference? We can't help if you don't TellTheDetails (<- link).


Not sure, but I am guessing the problem you are having is in the commented code, so you removed the most relevant part of the code: so we can't deduce your problem from your code either.

A couple of hints: your variable names are next to useless. It makes it hard to track what data you expect in each element. If you name them appropriate to the expected data it might be easier to read and work with. As it stands, I find it impossible to figure out what line of code is used to get what line of XML, because the element names are generic, you start at some point that doesn't exist in your example XML ("result") and your variables are repetitive, take the name of the XML tag rather than the data it should represent.

You might consider using XPath to select the proper rows/rowsets for the requiredSkills, etc... For example, assume you have a Node pointing to a <row ...> for a particular skill:


It has been a while, so the XPath and the rest of the code might not be quite right, but it should get you started. See http://docs.oracle.com/javase/tutorial/jaxp/xslt/xpath.html
 
simon did
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks alot for the replay i goth it working with the code you posted :P

sry if my problem discription was bad

and thanks for making me aware off xpath i think i might change all my code to xpath becouse i think it's simplere :P
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic