Previous Blog Next Blog
Prev/Next Blog
by date

XMLObject - TGB/TGE

XMLObject - TGB/TGE
Name:David Higgins
Date Posted:Dec 25, 2006
Rating:4.7 out of 5
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for David Higgins

Blog post

XMLObject for TGB/TGE using Expat




I put together this little resource for a prototype I'm working on, and figured I'd share the resource with the community.

Basically, it's just a simple "XMLObject" in C++, exposed to TorqueScript. It utilizes the Expat XML Library to perform SAX parsing of XML documents.

I exposed two methods to the console, which are "parse" and "parseDocument". Both methods take in a single string;

void parse(const char *data);
void parseDocument(const char *data);

If you have a string of XML you would like to parse, such as a string obtained from a network resource (SOAP, XML-RPC) you can pass the string to parse(), but if you have an existing XML document you can call the parseDocument and pass a filename.

Both functions initiate the generic Expat SAX callbacks for element triggers, these callbacks are as follows (these are the TorqueScript methods in -your- code that are called from the object);


onDefault(%data, %len)
onElementStart(%name, %attributes)
onElementEnd(%name)
onCharacterData(%name, %data)
onProcessingInstruction(%target, %data)
onComment(%data)
onCdataSectionStart()
onCdataSectionEnd()



%name is always the name of the element that the remaining data is contained in
%data is always free-form data, always in the form of a string
%attributes is a SimSet containing SimObjects with Dynamic Fields for AttributeName and AttributeValue
%len is an integer denoting the length of %data
%target is unknown, specific to the Processing Instruction and taken right from Expat (untested).


Included in the ZIP file are;


engine/source/ZoulCreations/XMLObject.cc
engine/source/ZoulCreations/XMLObject.h
engine/lib/expat2/*.h
engine/lib/expat2/libexpatMT.lib
games/XMLObjectDemo


To get this resource working, you need to make some modifications to your project, in my case, I modified the VS2005 Solution, and will post an update to this resource at a later date with Makefile modifications that work on all platforms (if anyone else wants to before then, thats fine).

Here are the modifications i made;

Extract the resource into your TGB directory, it should put the files where they need to go;


  1. Open your T2D solution in VS2005 (2003 should work the same?)
  2. Add a new "Filter" to your T2D project, call it "ZoulCreations"
  3. Add two existing files to this Filter, XMLObject.cc and XMLObject.h (locate them in engine/source/ZoulCreations)
  4. Edit the T2D Project's Properties
  5. Goto the Linker->General Properties
  6. Add "../../lib/expat2/" to the "Additional Library Directories"
  7. Goto the Linker->Input Properties
  8. Add "libexpatMT.lib" to "Additional Dependencies"
  9. Add "MSVCRTD" to "Ignore Specific Library"


Save changes, and rebuild the T2D Project.

The expat library can be obtained from expat.sourceforge.net/

All I did was compile the expat library first, then linked to the pre-compiled static expat lib I created.

In Linux and OSX, I would assume you can just simply build the static expat library and place it in your standard 'lib' directory.


Download Here


David Higgins
Programmer
Gear Worx Productions


Recent Blog Posts
List:11/19/07 - Cacheable Web Resources... Oh My!
09/29/07 - The Adventures of Coco the Gorrila in: CocoNuts
09/23/07 - How's it all Add Up?
07/11/07 - Ever wondered how to get your game project update to the rest of the team?
06/30/07 - The dog ate my homework, I swear!
06/20/07 - My latest news, and the new site I just launched ...
05/09/07 - $5,000 sound interesting?
05/01/07 - What Time is It?

Submit ResourceSubmit your own resources!

Clint Herron   (Dec 30, 2006 at 04:06 GMT)   Resource Rating: 5
Looks fantastic!

This seems much simpler and more bare-bones than the XML Console Parser resource.

Thanks so much for sharing this with the community! This might be just what I need...

--clint

You must be a member and be logged in to either append comments or rate this resource.