aspose file tools*
The moose likes XML and Related Technologies and the fly likes which parser to use Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "which parser to use" Watch "which parser to use" New topic
Author

which parser to use

John Gregory
Ranch Hand

Joined: Oct 05, 2006
Posts: 118
Have a question as I'm new to xml parsing.
Say my data looks like:
<contact-list>
<contact>
<name>Mike Green</name>
<home-phone>555-1234</home-phone>
<cell>240-1234</cell>
<email>abcd@hotmail.com</email>
</contact>
<name>Dave Brown</name>
<home-phone>555-2224</home-phone>
<cell>240-2234</cell>
<email>wxyz@hotmail.com</email>
<contact>
</contact>
</contact-list>

Ok, using a sax parser, I could print out all the elements. But,
what if I had a situation where I had a String "Mike Green" and
based on that, I wanted to grab his phone number. Aside form the
name, any of the fields may be blank.

I'm not sure which parser to use. I've looked at the tutorial and
I could print out each field, but not sure how to grab info based
on what I want to do. The DOM tutorial shows is how to print a
tree structure and I think this is what I want, just not sure how
to proceed.

Thanks,

John
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

Solution is DOM IMPLEMENTATION + XPATH.

XPATH - XPath is language used to navigate through elements and attributes in an XML document.

Best start up Reference for XPATH


Try dom4j library.


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: which parser to use