Parsing XML with C++
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
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. :)
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. :)
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).
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.
If you need more stuff, a full packade XML parser library, I'd go with Xerces.
Another vote for TinyXML. I can't see many reasons why you'd need to do validation in a computer game, so TinyXML should be fine.
ive used tinyxml for 2 of my projects and its worked a dream.
tinyxml does validation, by returning null pointers on an error.
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...
I also found TinyXML good (tho I haven't used any other xml parsing libs). It has worked fine for me.
you need to do validation FOR SURE, in any game that wants to let the users modify the files ... for modding ...
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement