I need an XML library that doesn't suck.

Discussion in 'Game Development (Technical)' started by Backov, Jul 8, 2007.

  1. Backov

    Original Member

    Joined:
    Oct 23, 2005
    Messages:
    812
    Likes Received:
    0
    Well, here's the thing - I usually take whatever I've got access to (libxml, built in Java XML, whatever) and wrap it so that it works the way I like it. That works.

    But, it's struck me that there's probably one out there that works just the way I want it to.

    I want to be able to use XPath to get nodes and list of nodes easily and I want to be able to do stuff like float val = node->attribute["xcoord"]; or whatever and have it give me a variable of type float even though the xml might read xcoord="10"

    Anyone have any suggestions? libxml works but I'm not fond of it. I want a system where it reads in the XML file all at once and stores it in a nice tree, so SAX is out (I believe)..
     
  2. Applewood

    Moderator Original Member Indie Author

    Joined:
    Jul 29, 2004
    Messages:
    3,859
    Likes Received:
    2
    We've used TinyXML from (I think) sourceforge. It doesn't behave exactly as you describe, but we've nevertheless found it very easy to use.
     
  3. ChrisP

    Indie Author

    Joined:
    Feb 5, 2007
    Messages:
    971
    Likes Received:
    0
    Seconding TinyXML. It's a great little library, and probably the only implementation of XML for a mainstream language I've seen that doesn't suck for gamedev purposes. (Apache XML, I'm looking at you.)

    It is on Sourceforge, but the main website is here: http://www.grinninglizard.com/tinyxml/index.html

    If you want XPath you'll probably also want this companion library (which I haven't used): http://tinyxpath.sourceforge.net/
     
  4. Backov

    Original Member

    Joined:
    Oct 23, 2005
    Messages:
    812
    Likes Received:
    0
    Alright, thanks guys, I'll give that a try tomorrow at work.
     
  5. sulaiman

    Original Member

    Joined:
    Aug 2, 2004
    Messages:
    20
    Likes Received:
    0
    Just another vote for TinyXML. It's stable and simple to use. Plus since it's a small library, it's easy to modify if you need to.
     
  6. Sol_HSA

    Indie Author

    Joined:
    Feb 27, 2005
    Messages:
    470
    Likes Received:
    1
    I've used tinyxml in several projects, game and otherwise, and I can heartily recommend it.

    Don't expect it to cope with every possible xml file out there though. For projects where you create the xml files yourself for it to read, it's perfect, but at least at some point some adobe tools managed to spit out xml files which tinyxml could not parse.
     
  7. Bad Sector

    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    5
    I use libbadxml, my own handcrafted parser which can load and save simple XML files. It is written in plain C, it's code is around 700 lines, made of two files (one header, one source) which you can include in your own projects (but you don't have to, you can build it as a static library) and can understand most XML files out there. It doesn't support DTDs or namespaces (it'll just include the namespace parts in the names so you can still use them, though) or any other fancy XML stuff that isn't used that often (especially for simple XMLs :). Also it can save XML files and it'll try to make them human readable too :).

    When it loads a file, it loads the *whole* file (so it's not suited for really huge files) and creates a tree structure with the nodes of the file. When you save the file, you can save to a file directly or generate the XML code for the tree. You may even generate XML code for a branch only.

    The library is licensed under the MIT/X11 license, which practically means you can use it as you like.

    Note that while i used this library here and there, i prefer to use libbadcfg which -although it doesn't provide write support- uses a more clean syntax for tree structured files. Unlike libbadxml, libbadcfg is really tested in *many* projects of mine and used for many things, including the world format of my previous 3D engine's world editor.
     
    #7 Bad Sector, Jul 9, 2007
    Last edited: Jul 17, 2007
  8. filharvey

    Original Member

    Joined:
    Feb 4, 2005
    Messages:
    104
    Likes Received:
    0
    I've used TinyXML in the past, but the problem I had on Console development (PS2 / DS / Wii) is that it takes up a lot of space building up the DOM table. Even for a very small file. And at the time I was using it, anything more than a 1Meg killed the stack. Also on the DS, even less is needed.

    I moved to using Expat, The main differences here is that the library does not build up a DOM tree, it uses call backs when it gets a XML event.

    Basically it will send a call back on entering a tag, exiting a tag, and when parsing any text between tags.

    Attributes, are available to be read on the Enter Tag. The over head for this can be as low as 1k.

    Phil
     
  9. Applewood

    Moderator Original Member Indie Author

    Joined:
    Jul 29, 2004
    Messages:
    3,859
    Likes Received:
    2
    Phil Harvey ? I'm sure I know that name from somewhere not here. Mirage ?

    It's funny you said that, as we started with ExPat and moved to TinyXML because the callback nature of it did my head in. I understand it's far more efficient, but we solved that problem by not having massive xml files. :)

    I can at least say that of the non-DOM libs we tried, ExPat seemed the most stable.
     
  10. Bad Sector

    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    5
    We use Expat for XML parsing in Theseis. I can't stand it's callback-based mechanism so i wrote a wrapper that builds a DOM tree.

    Now i only need to convince others to use libbadxml... :p
     
  11. filharvey

    Original Member

    Joined:
    Feb 4, 2005
    Messages:
    104
    Likes Received:
    0
    Paul,

    yes same Phil Harvey
     
  12. Applewood

    Moderator Original Member Indie Author

    Joined:
    Jul 29, 2004
    Messages:
    3,859
    Likes Received:
    2
    Have we had this conversation before ? lol
     
  13. jimflip

    Original Member

    Joined:
    Aug 5, 2005
    Messages:
    75
    Likes Received:
    0
    I'd be interested in seeing your XML code 'Bad Sector' as I'm making changes to our library data loading. Your link doesn't seem to work.

    Thanks,
    Jim.
     
  14. Bad Sector

    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    5
    Correct link (fixed above too).

    I'm lame, i linked to my hard disk :p
     
  15. Backov

    Original Member

    Joined:
    Oct 23, 2005
    Messages:
    812
    Likes Received:
    0
    By the way, I found the winner - it's TinyXML++ - a C++ wrapper overtop of TinyXML that takes the ancient C++ interface of TinyXML into modern times. Quite nice. Combined with TinyXPath, it appears I have what I need.
     
  16. stiill

    Original Member

    Joined:
    Feb 13, 2006
    Messages:
    108
    Likes Received:
    0
    Thanks for the tips. I just grabbed TinyXML++ to replace the Popcap engine's stock XML functionality (it's limited to the NextElement function, and... the NextElement function). Works as billed.
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer