Tim
Tim

Reputation: 20360

getting XML data from Xerces (c++)

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?

Upvotes: 1

Views: 3831

Answers (3)

cytinus
cytinus

Reputation: 5644

If you use the XercesDOMParser, there is still no way to request a specific key value pair after the document is parsed. I ran into the same problem recently, and while iterating through the DOM tree I stored all the key value pairs in an STL map. Then you can request key value pairs from the map later in the program.

Upvotes: 2

Raj
Raj

Reputation: 22926

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

Upvotes: 2

anon
anon

Reputation:

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.

Upvotes: 5

Related Questions