I just did some testing with a parser I downloaded from the site I mentioned way above, and it parsed through a 2mb file in about 60ms or so. Incredibly fast...
I use XML every day in my work and i must say that XML i very powerful format. I can recommend to use the IBMs XML4C which i find the most mature XML lib around. Remember that XML format supports attributes which makes it great in a RPG.
I would agree that a binary format is faster to load, but XML is so great to work with, and XML editors is out there so you can start making the files easy.
DOn't get me wrong I love working with XML and recommend its use as a interprocess/computer communication protocol (SOAP anyone? My only comment was that binary formats are still more useful in certain situations. In Alien's case, XML is well suited to the task. As already mentioned, high-speed FPS games should use binary encoded formats because that is the most efficient way to transfer data. A bank trying to communicate with an insurance company and do data transfers should use an application XML (with the XML doc being encrypted before being sent - obviously).
Strangely, and maybe it is only for simplicity, people refer to XML as the actual language/protocol. XML is a meta-language which you use to define your own language. Your defined language is then typically named "MyLanguageXML", MathXML or RPGXML, SOAP, etc.
I've been working with XML professionally for the last 3 months and I do like it quite a bit (using a custom built C++ parser).
I''ve devised a general purpose solution over the past few years. I originally created a parser for an ini like language, which read all the data into a 2 level heirarchal structure for me to access later. Like this.
and I worked the access class over until it was fairly efficient and very helpful in finding common errors in the text. Then I started looking at XML for other things ... and came up with this ... and XML INI format - with a DTD ... so now the XML parser does the work my ini parser used to do ... and other people can use my format just my me giving them the DTD ... nothing else needed. Also important was the ini to xini converter ... which let''s me do what I now do ... which is this.
RAPID PROTOTYPE - INI format
WORKING VERSION - XINI format
LATER DEVELOPMENT / OPTIMIZATION - special purpose XML format with unique DTD ... and a converter between xini and special purpose xml format. This lets me impose all of the relationship rules I want on certain sections of my data, while letting the rest just be general xini .. so they must be well formed, but data content is unchecked.
When I want the user (not a fellow developer) to modify the data ... I put that section in it''s own file, in plain old INI format ... and my parser just reads it in and merges it with the other sections. Average people are NOT structured thinkers and would be much more comfortable with the normality of small clean INI files.
parsers ... I''m currently testing the apache parser which is Xerces-C available at http://xml.apache.org
which is xml .. but it brings up a very important issue people should think about ... why is he using ATTRIBUTES for all of the fields of data except one??? this makes no sense. If he wishes to use attrubutes this heavily then he should go all the way and make life MUCH easier.
when deciding wheather to place data in attributes or in sub-tags there is a lot of room for discretion (choice) .. but please be consistent. Some people use attributes for details inheirant in the object and sub-tags for distinct child objects .. which makes sense in the RPG world thing ... but making good DTDs is really an art very similar to making a good API for your classes ... or anything else ... it''s all about the way YOU make associations about the data and their relationships.
I'm pretty new at the whole XML thing. I put together my xml file, but I was wondering how I load the file into my game? Is it the same as loading a binary file more or less?
I know this is kind of a stupid question but the documentation for the xml class and parser I'm using tells you every detail you'd need except how to call in the file.
I'm assuming that a call in the game itself would go something like this:
xml.character[5].name[0].last[0].value
This would ideally bring back the value from the following: (let's assume this is the 6th character on the xml doc)
< character > < name > < first > Homer < / first > < last > Simpson < / last > < / name > < / character >
(sorry about the unnecessary spaces. I don't know how to put my code in a box so the formating doesn't get all messed up )
Zoe- Every parser is a bit different, which one are you trying to use? I can''t help much for anything but the Microsoft DOM (in VB6 and .NET). There''s a Load() method on the DomDocument object...which has a filename for parameter. There''s also LoadXML() that converts an XML string to nodes.
The calls to get data are a bit more extensive than that, and the XML parser has some added overhead, so you''ll want to convert the nodes to your objects immediately. Someone else will have to give you a C++ sample...
Interesting that people are knocking on .XML because a binary format is supposedly faster. What they fail to realize is that you can LZW compress the XML code into a binary format and write a loader for it that uses LZW natively by reading it into a data structure.
You get the best of both worlds that way. You can edit your .xml file and make additions and then use some algorithm to convert it to a binary format and add the code to your program to do both. Just because XML is self-describing doesn''t mean you can''t write some sort of app to convert it to a binary file somehow. The advantages of XML become apparent when you need to have your developers or users work with the data directly or you need a common storage medium.
Sure, using xml in its pure form can introduce some overhead, but as is with most things there are workarounds that could make it even smaller than a binary format. It just depends on how lazy you are ;-)
Anesthesia"If you like heaven so much, GO THERE! Leave me the hell alone!"
The sheer act of compressing that data consumes time. The you need to uncompress the data, then parse it. Once again you run into the parsing issue. I really don't think an application of XML would do well as a protocol for an FPS game.
I hardly think that reading,
<player> <id>1954</id> <name>Dire Wolf</name> <position> <x>100</x> <y>200</y> <z>100</z> </position> <speed>10</speed> </player> // 128 bytes (not including spaces or newline - not compressed)
as compared to reading in:
typedef struct tagNetPlayerInfo { unsigned long id; unsigned char nameLen; unsigned char* nameString; unsigned long x, y, z; unsigned long speed; unsigned char padding[3]; } NetPlayerInfo, *PNetPlayerInfo; // 30 bytes (including 10 bytes for the memory allocated for nameString("Dire Wolf"))
Compression or not, reading the XML data will be much slower than the binary format. I tried compressing the above XML using Winzip and could only get it down to 95 bytes.
Now just assume that this packet has to be sent 10 times a second to each player and we have 16 players online:
95 x 10 x 16 = 15.2 Kilobytes/second for the XML version (compressed). 30 x 10 x 16 = 4.8 Kilobytes/second for the binary version.
Granted you probably would never send this type of packet repeated but you get the idea. The binary format is a simple read (and allocate for the name). The XML version needs to parse each tag and value then place them into the corresponding containers (whether it be the data members of a CPlayer class or what not).
XML WILL be slower but feel free to prove me wrong
Now on the other hand,
I'm all for using XML in games for defining characters, scripts, items, worlds etc. I'd even go as far as saying XML could be used as a game protocol language, but not for all game types (FPS etc). Sometimes binary is better.
Now when working on eBusiness solutions I'm all for XML. Period. Binary data can be trouble some to work with and extend while XML is well suited to the task.