Advertisement

XML as opposed to text files...

Started by May 16, 2001 10:22 AM
29 comments, last by Alien Tesh 23 years, 8 months ago
So your argument is basically

"I can''t get text format to work so I am going to use XML"

ROFL!

AP: Actually....yes...that''s pretty much my argument. I had heard rumblings that XML simplifies the use of text and binary files being added to an array.

Don''t get me wrong... through some research, I''ve realized that the full blown version of XML is bloated and a memory pig, but... and I say but... I found the above site which eliminated those concerns.
Advertisement
Hehehe...

I have considered using XML on my projects as well... You will get many added benefits as others here have pointed out. Some type of LZW compression scheme can take care of the bloated size (it''s beyond me why something as size-critical as the internet would depend on a text-based scheme with no compression to describe its data) and there are some small parsers out there, but you can also do searches on accumulated data...

Your reasoning for doing so is pathetic, I''m sorry to say. It''s fairly easy to grab data from a text file into a data structure using file streaming. Ex:

typedef struct
{
int Age;
string Name;
int Class;
}
person;

int main(void)
{
person Anesthesia;

ifstream inFile("Filename", ios::in);

inFile.read(&Anesthesia, sizeof(Anesthesia);

cout << Anesthesia.Age << endl;
cout << Anesthesia.Name << endl;
cout << Anesthesia.Class << endl;

inFile.close();
}

Don''t ask me if the code fully works... I can''t test it, but I know it''s very close. If you''re using C, it''s not much more difficult to do (what was the function, fread??). Let me know and I''ll send you an example for that.

There''s no need to get frustrated about it. Just keep a clear mind and look to everything as the next big challenge. You will find if far more rewarding seeking out a solution than complaining about a problem and changing your focus, which even you must agree is pretty lame.

If you want to do XML, do it... But do it for the right reasons. Coders are logical, and they only become emotional when they are done with their work! ;-)

Later







Evo,

XML Doesn't really save you from iterating over data that doesn't apply to the criteria. It is still top down, so the file pointer must still traverse to the 100th MB. Using XML removes the possibility of being able to jump through a file without have to read the whole file in. Think of it, how do you find the next monster tag? You have to keep reading in characters until "&ltmonster>" is found. Then you can do your name check.

Most binary formats are tagged in some way, and if the tag is a simple 4 byte type id (i.e. monster) the comparison is much quicker than comparing the string . Not to mention binary offsets. Using binary you can just move the offset pointer around. The name of the monster will still be a string comparison so XML and binary are on equal footing there...

BTW Lets not forget that to load XML data you have to parse each tag to get its name so that you know which data member to store the value in. Binary has a fixed structure so you can just read in a chunk, send it to a class constructor and let the constructor sort it out.

typedef struct {
unsigned long blockType;
unsigned long blockSize;
unsigned long nextBlockOffset;
unsigned char* dataBlock;
} DataBlock, *DataBlockPtr;

This would faster than an application of XML to the same situation. Still, you wouldn't be able to read it very well with just your eyes. XML is also more extensible due to DTDs, attributes and being text based.

Dire Wolf
www.digitalfiends.com

Edited by - Dire.Wolf on May 16, 2001 5:02:55 PM

Edited by - Dire.Wolf on May 16, 2001 5:25:37 PM
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
Dire-
The SAX2 parser works totally differently than the DOM. You don't load anything into memory that you don't want, it's extremely small and fast. It doesn't load the entire structure into memory, nor does it retain the parser after you're done with it. The drawback is that it only reads sequentially to get you the data you need.

.Edit. Agreed about the top-down reading, equal ground there...don't remember what I was thinking.

Alien-
Most business transactions haven't changed since the 70s. Plain text, formated for a person at a terminal, and screen-scraped by a computer on the otherside. I work on a team that does this crap...and it's a pain in the ass. Some data sources changed to "structured text" in the late 80s which is basically the binary format described by Dire Wolf. Now these sources are moving over to XML. For some reason it's just progmatically easier to use a standardized format that is self-descriptive and human-readable. Especially when debugging! All the hardwork is done for you, you've just got use the parser and pull the tags out.


Epolevne

Edited by - Epolevne on May 16, 2001 7:35:29 PM
I completely agree that XML is powerful when it comes to defining protocols for communication between different applications or computers. It provides an extensible and self-documenting format which is key for business to business transactions. I'd rather work on a system that uses an XML application for communication than differing binary-encoded formats.

Still, binary is just plain better for certain uses. If Alien is just using XML because he is having difficulty reading in plain non-tagged text, then that is a wrong way to use XML. Actually using XML for an RPG game would be pretty cool. You could describe equipment and related properties/attributes, characters, monsters, towns, npc etc. You could call it RPG XML That, in my opinion, would be a good application of XML.

Dire Wolf
www.digitalfiends.com

Edited by - Dire.Wolf on May 17, 2001 12:13:27 PM
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
Advertisement
I think I should clarify something...

It''s not that I can''t get text/binary files to work in general, I just couldn''t get them to work the way I wanted them without tons of problems arising in other parts of the game.

Dire... pretty much made my point by his comments about the RPG. That is the major reason I''m going with XML. Reading all the stats, etc. in was a pain, primarily because of the shear number of them. And since my game is in the development stage it makes things that much harder when I can''t determine what stats are what.

One last thing... I''m under the impression that many of the negative comments have been based on the idea that many think this is an internet based... This is untrue... (I could be misunderstanding the posts, but that''s the way it seems )

Anyway though...thanks for all the posts (it has certainly helped my decision.
I''m actually using XML in a similar manner. I''m using it throughout the game to allow for end-user customization. My command interpreter uses an XML file to load it''s commands, syntax, and which scripts to call. It works rather well (if I do say so myself :-)


Epolevne
I have to say I''m amazed to see all the negative comments about XML. I''ve been using XML for over a year now (professional and otherwise) and I''m very satisfied with it.

About the size. Of course XML will be slow if you''re storing all your 100MB data in one single XML file. The solution is simple: just split up your data and store it in different XML files, then you can have the OS''s file system do part of the work for you, by having it look up the files. And if you can''t split up your data, hey, just reorganize it !

About the speed. I''ve written my own XML parser using Flex and it''s very fast. Sure, it doesn''t support all the nitty gritty features, but who needs them anyway? Mine just parses standard XML files with tags and comments, etc. and it works fine (and fast). If anybody wants it, just ask me and I''ll put it on the web. Actually, it already is, but it''s buried in a bunch of other code. Anybody who''s interested: check it out at http://users.pandora.be/dormeur#downloads.

I agree that it''s not very interesting to use XML as a high-speed communications protocol, but if it''s only for one-time reading or writing of config files and savegames, it''s perfect. I am using XML in my network communications protcol, but that''s for debugging purposes, and I don''t need high speed communications anyway. But I''m also using it as a config file format, that''s read at startup of my game and it''s used to build my entire GUI. Very flexible, and easily modifiable.

The big advantage of XML, next to human and machine readability, is that you only have to build (or copy, if you will ) one parser and you can use that to read all your files. The parser already checks the file for well-formedness, so it raises errors if the file is malformatted. The only thing the programmer has to do is check if the required tags and their attribures are available, and that''s a lot easier than having to clear whitespaces and the works all the time!

Dormeur
Wout "Dormeur" NeirynckThe Delta Quadrant Development Page
Actually you don't have to manually check for the correct tag structure. XML's can have associated DTD files (Document Type Definition) that contain what the correct syntax is. So, once you create the DTDs you can just use it to check well-formed XML. I know the DOM can use DTDs...but if you wrote your own parser then the burden falls on you.

*snipped tagged example*

There are lots of resources around the internet to help you out when writing DTDs.

Epolevne

Edited by - Epolevne on May 18, 2001 2:52:21 PM

This topic is closed to new replies.

Advertisement