Archived

This topic is now archived and is closed to further replies.

easy way to use an XML parser in C++?

This topic is 5576 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

Hey I''m just trying to do an easy way of saving/loading my high scores, and I was thinking of doing a quick XML grab.. Has anyone used an XML parser with Visual Studio? Is it easy to setup? I just wanted to do something like:
  
<highscore id="e0">
<score>1200</score>
<player>Iolo</player>
</highscore>
<highscore id="e1">
<score>1400</score>
<player>Dupre</player>
</highscore>
  
You get the idea.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Take a look at the MSXML parser. It''s pretty well tuned as it is used by SQL Server and other high demand implementations in the enterprise space:

http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/766/msdncompositedoc.xml

Cheers!
Colin

Share this post


Link to post
Share on other sites
use COM.

there is a COM object called XMLDOM in IE5 which can be used for XML. Search MSDN. You can use XML documents with as little as 10 lines of code.

IXMLDocument is the parent interface.



[edited by - jwalker on September 10, 2002 10:25:27 PM]

Share this post


Link to post
Share on other sites
I took the easy way out... I wrote my own xml parser

-----------------------
"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else''s drivers, I assume it is their fault" - John Carmack

Share this post


Link to post
Share on other sites
Wow, thanks for the responses. I was hoping that there would be an easy way to implement an XML parser of some kind in my application..

Hmm I''ll have to look at that COM object more carefully though. I don''t want to force anyone playing my game to have IE5 installed.

Thanks again for the responses all!

Share this post


Link to post
Share on other sites
I'm using Xerces, too.
By the way, this isn't the correct formum for this question.

PS: nice to see another Ultima fan!

[edited by - VolkerG on September 11, 2002 3:20:33 PM]

Share this post


Link to post
Share on other sites
XML parsers are pretty easy to write assuming you want a basic version of XML. i mean, people chose XML as a good data passer between apps b/c it's human readable and easy to write a parser for.

basic class:


      
#include <vector>
using namespace std;

/*
* example node unit
*
* <nodeName property1="foo" property2="bar">message</nodeName>
*
* children are sub nodes contained beween the <nodeName> and
* </nodeName> boundaries:
*
* <nodeName property="foo">
* <childName property1="foo">message<childName>
* </nodeName>
*/


struct XMLNode {
vector <XMLNode *> children;

vector <char *> properties;
char * name;
char * message;
};


then you just write a simple recursive parser that loads info into your root tree object (which is also of XMLNode type). Finding elements is a simple recusive tree traversal to find an XMLNode of a particular name : property match. The whole thing gets very very easy if you replace the char * vars with stl string vars. shouldn't take very long at all to write/debug and incorporate into your game.

especially for something as simple as what you are proposing, you don't really need all the super functionality of a pre-written deal. obviously you make the decision to write your own. if you don't want to be hassled writing the parser use someone elses. (i.e. follow the don't reinvent the wheel camp which is certainly a valid camp).

anyway, just a suggestion in case you wanted to DIY...

-me

[edited by - Palidine on September 11, 2002 3:39:03 PM]

Share this post


Link to post
Share on other sites

Looks like people have already done quite a bit of experimentation already! Way cool

My only concern is that I kinda only want a .dll or .lib file to link to during compilation/runtime that can just be in the same directory as my executable.

the Apache XML documentation was getting pretty heavy into setting environment variables when I fled the site.

Not that I have anything against Apache, but I''d rather deliver something that ANY gamer can play: even one who does NOT remember using emm386 (remember THAT? *grin*)...the point being I just want the customer to be able to click "play" and that''s it.

I''ll take a look through the others and see what they offer as well..

shouts out to all, and yes, Ultima REALLY kicks ass.





Share this post


Link to post
Share on other sites