XMLObject for TGB/TGE
by David Higgins · 04/03/2007 (11:24 am) · 2 comments
I have written this resource for my own uses, but thought it would be useful to the community. I posted about it in a plan a while back, and figured it was time to put it up in the resource section.
You can download this resource on the Gear Worx Productions website in the downloads section.
Here's a copy of the .plan that explains usage, and how to compile it into the engine source:
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);
Included in the ZIP file are;
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;
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

You can download this resource on the Gear Worx Productions website in the downloads section.
Here's a copy of the .plan that explains usage, and how to compile it into the engine source:
XMLObject for TGB/TGE using Expat
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;
- Open your T2D solution in VS2005 (2003 should work the same?)
- Add a new "Filter" to your T2D project, call it "ZoulCreations"
- Add two existing files to this Filter, XMLObject.cc and XMLObject.h (locate them in engine/source/ZoulCreations)
- Edit the T2D Project's Properties
- Goto the Linker->General Properties
- Add "../../lib/expat2/" to the "Additional Library Directories"
- Goto the Linker->Input Properties
- Add "libexpatMT.lib" to "Additional Dependencies"
- 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

About the author

Torque 3D Owner Chad Kilgore
Being relatively new to XML, is it possible to query an XML document for specific data? If so, can an XMLObject perform this task? Is it a limitation of Expat or TorqueScript/engine exposure?