views:

949

answers:

4

How to read an XML file in a Visual C++ application?

I need to read an XML file in a Visual Studio 2003 C++ COM ATL application - unmanaged code. What library should I use: msxml, xmllite, other?

I need to check that the xml satisfies its xsd I've defined and then read it.

Sample code welcomed ;)

Thanks in advance.

A: 

It depends. Do you want:

  • to have your XML validated?
  • to force it to be well-formed
  • to produce a DOM?
  • to create your own structures in response to events?
  • to write portable code?

Different requirements, differemt solutions.

anon
+1  A: 

There are a lot of choices, we use the Xerces-C++ library which covers all the options, but isn't the most light weight of choices, but offers a lot of flexibility.

For starters you need to decide if you want a DOM style parser or a SAX style (event driver) parser.

Rob Walker
+1  A: 

I used tinyXML. It is very restricted(no DTDs, no XSL), but it loads XML-Files into doms, is very small and fast. If you just want to read an xml-file to extract information out of it: that is the way to go.

Peter Parker
A: 

I'm a huge fan of CMarkup. It has MFC and STL string versions and is written in unmanaged C++; ideal for all of my situations.

There's also a wrapper class for MSXML. There's a downloadable version available to experiment with and several samples/tutorials available online.

SAMills