Jump to content


X烯l - Xml Simplified

  • Please log in to reply
5 replies to this topic

#1 databot


    admin of moonlight games

  • New Member
  • 309 posts

Posted 14 March 2010 - 01:50 PM

So a while back GhostKeeper wrote a pretty nifty XML parser that would load the XML file of your choice and spit out a very nice tree structure for it. This was good, but lacked a lot that could make it really useful, such as proper dom style sub-element searching, editing, adding, and deleting elements, and most importantly saving these changes.

Today, after two weeks of work I proudly present X清L, a direct descendant of GhostKeeper's work.
X清L takes the base of simplXML, and expands it considerably, X清L's features include:
  • Adding, deleting, and renaming elements.
  • Supports writing tags, attributes and data.
  • Saves XML files.
  • A ground-up rebuild of the search functions to incorporate Dompath style searching (test\object[1]\settings\setting[8]) no more rewriting the search path based on position!
  • xml_new(), the ability to create a brand new xml document without having one to start.
Anything simplXML couldn't parse, this can't.
Also don't bother using entity whatevers, I couldn't figure out how to reimplement them.

Who to give credit to:
GhostKeeper: for the base of this code with simplXML.
Me: for improving on a great system.

  • 14/03/2010 - Added xml_dompath_count(), to count sub elements, easing automated searching.

Posted Image
Please note there may be the odd bug lurking somewhere in the code, so if u find it please let me know with as much detail as possible.

What is XML?
XML (eXtensible Markup Language) is a set of rules to define a tree like strucure for storing data. It is used for many things, from RSS feeds to XHTML.
Why use XML to store data?
XML is a excellent way to store data for a number of reasons.
In the case of games, savegames that use XML can automatically support DLC/updates because DLC savedata can be stored in a seperate node, not needed by the main game. Saving headaches with version compattibility.
It's structure also makes it very simple to search multiple elements for relevant data if setup correctly.

Edited by databot, 14 March 2010 - 08:43 PM.

  • 0
Scrip - Command line engine in the palm of your hands Get it Here
X清L - XML simplified

#2 travkliewer


    GMC Member

  • New Member
  • 21 posts

Posted 15 March 2010 - 11:21 PM

I really like your idea there, but I have a few, um, concerns, with it.

First, you code is kind of ugly and hard to read. (sorry, Perhaps, when you have time you could properly document it and make it easier to read.

Second, from what I can gather, you put the entire file into a single string, "contents", that you manipulate along the way. Wouldn't it be simpler to put into an array since you divide the contents string with a linefeed character anyways.

And last, and I'm having trouble understanding why you chose to do it this way, but you seem to have put all the data into one big long list of strings. With each string being either the name of tag, the name of an attribute or the value of either of those. You can't tell whether the string is data from a tag, or the value of an attribute, and I don't think that's part of the XML standards.

Of course I understand doing something like this is rather difficult with a program like Game Maker, and I certainly commend you on a such excellent achievement. I hope you can take my suggesting as kind and friendly thoughts of improvement and do with them whatever you like.

Oh, and by the way, I'm working on my own XML parser, with the same philosophy taken from yours and GhostKeepers design, and hope perhaps when (if) I get it done we can compare notes.
  • 0

#3 Krisando


    GMC Member

  • New Member
  • 1351 posts

Posted 15 March 2010 - 11:29 PM

The problem with all these XML interpreters (currently flooding the GMC) is they are all GML. =\ Very slow string functions and algorithm.
  • 0

Posted Image

#4 databot


    admin of moonlight games

  • New Member
  • 309 posts

Posted 16 March 2010 - 08:59 AM


First off thanks for posting.
Secondly i've just realised that i haven't updated this in a while, so people may have differing versions to the one i'm working on. as to the loading of the xml file, As i stated in my first post this script collection is an extension of Ghostkeeper's work (which included the xm_open function, much of which is beyond my understanding on hwo it parses the XML, most of my work on it involves manipulating the ds_grid output).

As to teling whats data and whats tag, i've pretty much solved that in the latest build, the orginal systems (simplXML) data structure was pretty good for constructing a xml, but from what i can tell you may have misread the format it is stored in.
The format is a ds_grid with tag,level,type. Given this data it's pretty easy to describe an xml file.

As for documentation and even a tutorial, yes i do realise its missing one, and i'll finish that up tonight.

In the mean time, i'm going to upload the current version i have, which has a somewhat basic tutorial on how to open, search and get data in terms of a savefile. I realise its not a perfect tutorial but its the best one available till i can do one tonight.
  • 0
Scrip - Command line engine in the palm of your hands Get it Here
X清L - XML simplified

#5 Shiny_


    GMC Member

  • New Member
  • 11 posts

Posted 16 March 2010 - 03:55 PM

I've previously written an XML parsing library that is, admittedly, far more sophisticated.
It's open source if you wish to look at it.

  • 0

#6 thecrazygamemaster



  • GMC Member
  • 785 posts
  • Version:GM:Studio

Posted 22 July 2012 - 09:27 AM

How would you, quite simply, open a XML file and read variables from it?



How would I grab the size variable?
  • 0