#### Archived

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

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

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

## 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 on other sites
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:

Cheers!
Colin

##### 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 on other sites
Use TinyXML !!! It''s a very good parser. Go to sourceforge.net and search for TinyXML. The API is easy and it''s fast. Use it and love it. Forget all the M\$ shit.

##### 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 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 on other sites
http://xml.apache.org/

When I look upon seamen, men of physical science, and philosophers, man is the wisest of all beings. When I look upon priests, prophets, and interpreters of dreams, nothing is so contemptible as man.

Diogenes

##### 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 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 on other sites
Forget Microsofts XML stuff. Go here for a good and easy to use xml parser.

[edited by - Jonus on September 11, 2002 7:19:47 PM]

1. 1
2. 2
Rutin
21
3. 3
4. 4
5. 5
frob
12

• 17
• 9
• 31
• 16
• 9
• ### Forum Statistics

• Total Topics
632614
• Total Posts
3007440

×