Skip to main content
gamedev.net
🔒 Locked

XML

Started by gimp Oct 18, 2000 at 10:29 PM 1 replies 450+ views
Original Post
gimp
gimp
Hi, I''m looking for a simple XML parser that can be integrated in to my code easily, perhaps something I can derive from to give my classes the power to load\save their data to a file. I''m planning on using this to store data about my world, like spawn points, mission properties, etc... I''e never used XML before but I think I understand the concept. Here is a sample of what I''d like to do(hope the html doesn''t screw it):
    

<?xml version="1.0"?>
<!DOCTYPE World SYSTEM "World.dtd">
// This is just a modification of something I found for a sales system. I''ll be reading some doco soon on a proper implementation

<World VERSION="1.0.0">
  <SpawnPoint>
    <PositionX="192.0355234" PositionX="192.035234" PositionY="5.035643" PositionZ="2.000000" />
    <Delay="1"/>
  </SpawnPoint>
</World>

    
..and I''ve started playing with a dtd. I''ll only be storing\retrieving simple data like this so I have no need to a massive 100% correct implementation. I''d like source so I can incorperate the code in my app rather than use a dll ( I''m crossplatform with SDL ). Could anyone suggest any source and suggest anything that they think I should know\read. (I''m not buying books for a while, 15 books in 3 months is a little too much) Many Thanks Chris
Chris Brodie
soehrimnir
soehrimnir
If you are using Java, there are two types of parsers.

- DOM: Document Object Model. This will parse your XML as a document tree. In your example ''World'' would be the root element, and ''SpawnPoint'' is a child node of ''World''.

- SAX: Simple API for XML. This will just go through your XML and throw an event whenever a begintag or and endtag has been found. You just have to catch these events and do anything you want to be done.

The DOM parser is easier to work with, but SAX is faster. This could be useful when working with really large files. It requires a bit more work though.

I just did a search on SAX, for example, and I found they had an API for Perl and Python, too. So I suppose there will also be one for C++.
Neophyte
Neophyte
I''ve done some work with XML in Java myself, but have no experience with XML in other languages. For Java I personally favour Apache''s Xalan and Xerces (can be found at http://xml.apache.org), but there are many other good parsers and processors out there. Take a look at http://www.xml.org for lists of resources and stuff.

Also, you say you''re only going to use simple XML-files, and are not all that heavy on everything being 100% correctly implemented. In that case you have no need for DTD''s, as their only purpose is to make sure that the XML is correctly formatted according to specific rules.

-Neophyte



- Death awaits you all with nasty, big, pointy teeth. -

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.