Writing my own XML parser?

Started by
30 comments, last by SabreMan 19 years, 5 months ago
For a project I'm working on, I'd like to write my own XML parser. It really only needs to support innertext and attributes (along with node names of course). And it needs to be able to understand XPath for innertext and attribute lookups. I'm using XML to describe a series of locations for buttons (top, left, width, height, UV map, etc) and I dont want to require a specific XML parser with it (MSXML 3.0, blah, blah) So I figured, I'd just compile it into my program. Maybe someone can suggest another way to describe and store such data?
Advertisement
There are a bunch of alternatives. My question to you is have you looked at other xml alternatives (than msxml) first? Xerces and TinyXML come immediately to mind. Writing your own is an interesting exercise, but I wouldn't recommend it except as a learning experience.

For a major project these files can be very large as XML is quite wordy - on one of ours the total set of UI layouts was over 25 megs when in XML (okay it was a really big project). At this point we switched to a compressed binary format. For small projects though it can work out very well.
Yes. Someone else suggested the binary format. Problem is, I have NO IDEA how to go about doing that. I'm comfortable with XML. This will be a commercial project, so anything I use will need to be pretty much free to use.

Tell me more of this "compressed binary format"
If it doesn't parse all of XML it's not an XML parser. It is not a trivial thing to write.
Quote:Original post by petewood
If it doesn't parse all of XML it's not an XML parser. It is not a trivial thing to write.



Maybe I'll pass on writing my own then. Anything else constructive to say?
Quote:Original post by benutne
Anything else constructive to say?


I'm not sure you would like it.
Use TinyXML. It compiles directly into your program. That is, you do not link it in, it's just "part of your project" and it's built for simplicity (parsing config files and whatnot)
XML is overrated. It has all the limitations of a text file and none of the advantages of a binary file.

I have to weigh in here ...

1. If it doesn't do ALL of XML it is not an XML 1.0 (or later) compliant parser ... but that doesn't mean it is not USEFULL.

2. It is an extremely large project (HUGE) to make a compliant parser. But making a little dinky parser that loads basic child / value and attribute nodes is not that hard (my friend has done one in 4 days that suits HIS - and only his - needs).

3. However, writing your own is time that could be equally well spent learning about the abilities and usage of some existing ones, which would give you more features in the long run. (although a good exercise could be to spend 2-3 days writting one, THEN switch to a "real" one, to improve your programming a little and gain some knowledge of what goes on with a parser).

4. The XPath part of what you want to acomplish is not hard, but is not absolutely trivial, which makes me lean more toward a prepackaged solution.

Personally, I used to use Xerces back at version 1.2 or so ... and it was hard to learn at the time, and lacked some features - but it was better than the custom parser we had at my company at the time.

Then I used .NET for the last year, and in 2 days I had tons more features at my fingertips than with any custom solutions.

Then I went back to a cross platform C++ project - and tried to get my friend and me to use Xerces again ... he simply refused because we wasted 2 hours just getting the damn thing loading a file for traversing ... it is NOT easy to learn to start with - and does NOT let you ignore aspects of XML you don't care about at the moment.

If you try TinyXML please report back your opinion of it after just one half to 2 days ... I'd like to know if it's easy enough to try to recommend to others.
Quote:Original post by petewood
If it doesn't parse all of XML it's not an XML parser. It is not a trivial thing to write.


I suppose that's one way to look at it. But FWIW, on the last game I worked on we used a home grown XML parser that favored speed over being fully XML compliant. It worked just fine for parsing all our in-house XML files.

-John
- John

This topic is closed to new replies.

Advertisement