XML Console Parser
by Matthew "Ashteth" Kee · 10/24/2005 (8:00 am) · 22 comments
Download Code File
//------------------------------------------------------------------------------
// Matthew Kee
// Console Based XML parser for Torque Game Engine.
//
// This resource is based upon the TinyXML library and extends the resource:
// XML Persistence for Torque Objects
// By J. Donavan Stanley
// http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4238
//------------------------------------------------------------------------------
This resource extends the XML persistence "pickler" resource by adding an
XML parser console object. The main advantage of parsing XML from within
script is that it allows for easier conditional execution and object creation
(such as level loading). There are advantages to both pickling and script
execution which is why I chose to build this resource on top of the excellent
work of J. Donavan Stanley.
To install this resource, simply unzip the included source files into
your Torque / T2D base directory. If you already have the persistence
resource installed, there is no need to overwrite any files -- I haven't
changed the persistence resource in any way, I simply chose to include it
for added convenience.
At this point, you will need to alter your makefile "SDK\engine\targets.torque.mk"
by adding these lines:
SOURCE.PERSISTANCE=\
PERSISTANCE/tinystr.cc \
PERSISTANCE/tinyxmlerror.cc \
PERSISTANCE/tinyxmlparser.cc \
PERSISTANCE/tinyxml.cc \
PERSISTANCE/pickle.cc \
PERSISTANCE/xmlDoc.cc
And to the preexisting "SOURCE.ENGINE =\" designator, add:
$(SOURCE.PERSISTANCE) \
And to the preexisting "SOURCE.TESTAPP =\" designator, add:
$(SOURCE.PERSISTANCE) \
You may now execute the included demo. First, rename your current "client.cs"
file to something like "client_bak.cs". Then copy the included
file "client_xml.cs" and rename it "client.cs". You will also need to copy
the included file "level.xml" into the same directory as your Torque executable.
Note: This XML parser is stack based, so you will predominantly want to
move up and down the XML hierarchy logically rather than skipping
around indiscriminately.
Known issues: This resource loads files based upon the executable's active
directory and *not* the active mod directory. Furthermore, traditional Torque
filename designators like "~client/" do not work at present.
Presently this resource only implements the bare minimum functions needed to
parse XML files in TorqueScript. If you require any additional functions,
feel free to contact me (e-mail in my profile) or implement them yourself.
If you have any useful additions to this resource, feel free to contact me
and I'll see about adding the functionality.
Acknowledgment: The input file for this resource is based upon source
from the article: "Creating Moddable Games with XML and Scripting Part I"
by Oli Wilkinson
found at: "http://www.gamedev.net/reference/programming/features/modxml1/"
It is possible that in the future I will demonstrate a T2D space invaders
clone using XML for level loading. I don't promise anything though ;)
Update: Now contains XML write example.
//------------------------------------------------------------------------------
// Matthew Kee
// Console Based XML parser for Torque Game Engine.
//
// This resource is based upon the TinyXML library and extends the resource:
// XML Persistence for Torque Objects
// By J. Donavan Stanley
// http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4238
//------------------------------------------------------------------------------
This resource extends the XML persistence "pickler" resource by adding an
XML parser console object. The main advantage of parsing XML from within
script is that it allows for easier conditional execution and object creation
(such as level loading). There are advantages to both pickling and script
execution which is why I chose to build this resource on top of the excellent
work of J. Donavan Stanley.
To install this resource, simply unzip the included source files into
your Torque / T2D base directory. If you already have the persistence
resource installed, there is no need to overwrite any files -- I haven't
changed the persistence resource in any way, I simply chose to include it
for added convenience.
At this point, you will need to alter your makefile "SDK\engine\targets.torque.mk"
by adding these lines:
SOURCE.PERSISTANCE=\
PERSISTANCE/tinystr.cc \
PERSISTANCE/tinyxmlerror.cc \
PERSISTANCE/tinyxmlparser.cc \
PERSISTANCE/tinyxml.cc \
PERSISTANCE/pickle.cc \
PERSISTANCE/xmlDoc.cc
And to the preexisting "SOURCE.ENGINE =\" designator, add:
$(SOURCE.PERSISTANCE) \
And to the preexisting "SOURCE.TESTAPP =\" designator, add:
$(SOURCE.PERSISTANCE) \
You may now execute the included demo. First, rename your current "client.cs"
file to something like "client_bak.cs". Then copy the included
file "client_xml.cs" and rename it "client.cs". You will also need to copy
the included file "level.xml" into the same directory as your Torque executable.
Note: This XML parser is stack based, so you will predominantly want to
move up and down the XML hierarchy logically rather than skipping
around indiscriminately.
Known issues: This resource loads files based upon the executable's active
directory and *not* the active mod directory. Furthermore, traditional Torque
filename designators like "~client/" do not work at present.
Presently this resource only implements the bare minimum functions needed to
parse XML files in TorqueScript. If you require any additional functions,
feel free to contact me (e-mail in my profile) or implement them yourself.
If you have any useful additions to this resource, feel free to contact me
and I'll see about adding the functionality.
Acknowledgment: The input file for this resource is based upon source
from the article: "Creating Moddable Games with XML and Scripting Part I"
by Oli Wilkinson
found at: "http://www.gamedev.net/reference/programming/features/modxml1/"
It is possible that in the future I will demonstrate a T2D space invaders
clone using XML for level loading. I don't promise anything though ;)
Update: Now contains XML write example.
#22
05/19/2008 (7:28 am)
is it me or torque, but when i compile tinyxml with the TIXML_USE_STL define for stl usage, i get a zillion compile errors, but when using tinyxml without the stl support all compiles peachy . Is torque somewhat stl allergic? 
Torque Owner David Horn