This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which parser to use

 
John Gregory
Ranch Hand
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 502
Java jQuery Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic