Sign in to follow this  

Parsing XML with C++

This topic is 4729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Most of my coding has been with C#, and I like XML as a data storage format. I'm about to develop my next game in C++, and would like to use XML. A google on it pulls up a bunch of different libraries and tutorials. What libraries would you advise? I'd like something that's easy to use with VC++ 7.0. Thanks. -Nick

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I used tinyxml briefly. Had it working in just a few hours to read some files I invented.

I did not try any others, or even use that one much though. But if you don't get any better advice that is at least one that isn't awful. :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
xerces is what they are using here at work to parse game files, a much bigger library than tinyxml (my priority was learning the lib in less than 1 day when I chose tinyxml).

Share this post


Link to post
Share on other sites
We use TinyXML for our game and I like it. You're up and running in a hour or two. But it can't do validation. It's as small as possible, it's can parse a XML file and write a XML file.

If you need more stuff, a full packade XML parser library, I'd go with Xerces.

Share this post


Link to post
Share on other sites
I also have used TinyXML. I did have problems with it when dealing with large data files (only 20MB or so) since it used up about 1500% (15 times) the file size in memory footprint, after parsing the file into a full DOM tree. I modified the library to use a pull-parse method instead, and it now uses only the memory required to load the file into memory. I could feasibly remove that requirement also and go with a stream-based system that would lower memory footprint yet further. In any case, this modification was necessary to avoid hitting the 2GB address limit with larger files. Now I need to find a reliable way to write the XML out without needing to build a full DOM tree first...

Share this post


Link to post
Share on other sites
When I said it didn't do validation, I meant with a DTD or Schema.

Xai has a point. But unless you're aming for a game dev kit, then you don't have to care. Besides:
A) You can do a type of validation yourself, that's what I do. Write a wrapper, so when you're loading something then it type checks the data against the data in the file. Say you want to load a float and you get a char, that's when you kick of a error message and stop loading. Works very well :)
B) If you aim at modding, supply a tool that does the saving. No one should really have to be editing XML files when making a mode, that's pure evil :P

Share this post


Link to post
Share on other sites
If the validation is important to you, you could use a third-party web-service (like W3C's XML validator) to validate the document in conjunction with TinyXML's parsing for local tasks. For instance, each time a user wants to save to a previously validated document, you could run the parser against it; if it passes, send it to the web service. If the web service returns a success code, you allow them to save; if not, you can throw an exception.

Share this post


Link to post
Share on other sites
I use .NET XML processing when I'm in C# .. but in C++ I'm not happy with anything I've tried ... and plan to try TinyXML soon, for the simple stuff. Ruby has a great little XML library called ReXML, but that does nobody any good who doesn't use ruby (a good 99.99% of the world).

The problem with Xerces is, it very closely resembles the original DOM just as Java does in nearly every aspect, which has quite a few things which have been modeled more cleanly since ... and what's worse, not everything is supported, so you have a really large complicated API that is only 80% complete. And to top that off, they haven't provided the utility functions that could make life really easy, and instead give you sample projects for you to copy to roll your own ...

Basically, 3-4 years ago when I first used it, it was kinda hard, but impresive and featurefull for the time. Now its just a painfull dinasaur I still occasionaly have to use (when in cross platform C++).

Share this post


Link to post
Share on other sites

This topic is 4729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this