tags:

views:

393

answers:

2

I am a latecomer to XML - have to parse an XML file. Our company is using xerces already so I managed to cobble together a sample app (SAX) that displays all the data in a file. However, after parsing is complete I was expecting to be able to call the parser or some other entity that had an internal representation of the file and iterate through the fields/data.

Basically I want to be able to hand it some key or other string(s) and get back strings or collections of key/value pairs. I do not see that. It seems pretty obvious to me that that is a good thing to do. Am I missing something?

Is the DOM parsing what I want, or does that fall short too?

+2  A: 

Xerces provides both SAX and DOM processing. SAX parsing doesn't construct a model, so once parsing is finished there is nothing to examine or iterate through. DOM processing produces a tree-structured model which gives you what you want.

anon
DOH! I chose the wrong code samples to copy. Thanks
Tim
a model is exactly what I want (and what I was expecting)
Tim
+1  A: 

Check out the beginner's sample in this page YoLinux Tutorial on Parsing XML

Lenin Raj Rajasekaran