TorqueScript XML Object Loads

I’ve managed to get the XMLObject to a fairly useable point, so far, the following script, is useable:

[js]
function sceneObjectParser::onElementStart(%this, %name, %atts)
{
switch$(%name)
{
case “objects”: %this.objectBlock = true;
default:
if(%this.objectBlock)
{
%obj = new (%name)()
{
class = getAttribute(%atts, “class”);
superClass = getAttribute(%atts, “superClass”);
};
%obj.dump();
}
}
}

function sceneObjectParser::onElementEnd(%this, %name)
{
switch$(%name)
{
case “objects”: %this.objectBlock = false;
}
}

function sceneObjectParser::onCharacterData(%this, %name, %data, %len)
{
echo(“CDATA: —” @ %name @ ” – ” @ %data @ “—“);
}

function getAttribute(%atts, %name)
{
for(%x = 0; %x < %atts.getCount(); %x++) { if(%atts.getObject(%x).AttributeName $= %name) return %atts.getObject(%x).AttributeValue; } return ""; } $xml = new XMLObject() { class = "sceneObjectParser"; objectBlock = false; }; $xml.parseDocument("XMLTestFile.xml"); [/js] This will actually create instances of the objects identified by the xml elements inside of an "objects" node, for example, the following XML document was parsed for testing; [xml]




[/xml]

I’ve not yet thoroughly tested it, but once I find a useful and reusable XML format for Objects and Levels, I’ll start working on the saveXml and loadXml functions respectively, and add them as either ConsoleFunctions which take in any SimObject, or add them as addon functions to the base SimObject within the XMLObject.cc itself (little to no engine code should need to be updated for this resource to work effectively)

Leave a Reply