aspose file tools*
The moose likes Java in General and the fly likes Efficent way to parse XML Data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Efficent way to parse XML Data" Watch "Efficent way to parse XML Data" New topic
Author

Efficent way to parse XML Data

YuenLian Wu
Ranch Hand

Joined: Nov 16, 2005
Posts: 73
Hi All,

I am not too familiar with DOM API. Currently I have the following XML File,






And My Java Code to parse it will be:






My Code seems not too efficient as it's kind of hard code.
My ideal wish will be getting values dynamically, please teach me how


Myriads of Thanks


Transistor

[ January 11, 2008: Message edited by: YuenLian Wu ]
[ January 11, 2008: Message edited by: YuenLian Wu ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42641
    
  65
You might check out XPath. It allows you to retrieve specific nodes from a DOM tree without having to write the code to work your way through the tree. Plus, you can keep the XPath expression as a string in a config file, thus making the code a bit more independent of the XML structure.


Ping & DNS - my free Android networking tools app
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
intermediate bound...


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Lukasz Bajzel
Greenhorn

Joined: Dec 03, 2007
Posts: 26
We would suggest you to look at an open source API - JDOM. JDOM is an XML parsing API exclusively for Java. It uses DOM API to parse XML files and make the parsed data availabe as Java objects. It can be downloaded from jdom.org. Most the questions are answered in their tutorial, but if you need any help, let us know.


Hope this helps!

Sincerly,
Your friends at www.javaadvice.com
www.javaadvice.com - The place where your Java questions are answered directly.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Efficent way to parse XML Data