Game Development Community

XML tutorial

by arnaux · in Torque Game Builder · 10/16/2009 (9:55 am) · 5 replies

Hello,

I am looking for an XML tutorial to change a value in an xml structure.
For the moment I am using the functions from the common/gamescript/xml.cs
It's works fine to create an xml file or to read a Field value.
But then I am stuck to change a single Field value.
Any idea how to proced ?

Here this my code to create the xml file
%xml = new ScriptObject() { class = "XML"; };
%projectFile = "Filename.xml";
%xml.beginWrite( %projectFile );
%xml.writeClassBegin( "XML Section" );
%xml.writeField( "SomeData", "Random value" );
%xml.writeClassEnd();
%xml.endWrite();
%xml.delete();

The result is :

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<XML Section>
<SomeData>Random value</SomeData>
</XML Section>


And here my code to get a value from an xml file
%Xml = new ScriptObject(){class = "XML";};  
%Xml.beginRead("Filename.xml");
%Xml.readClassBegin("XMLSection");  
%SomeData = %Xml.readField("SomeData");  
%Xml.readClassEnd();  
%Xml.delete();

echo (%SomeData);

The result is :
"Random value"

Thanks for reply

#1
10/29/2009 (8:41 am)
I am in the wrong forum part ?
Or is it just impossible in torque script ?
#2
10/30/2009 (7:05 pm)
I can't claim to have spent much time with torque's xml writer but %xml.writeField( "SomeData", "new value" ) works perfectly fine to modify a previously existing field. It's how I'm storing my savegame data on the iphone.

It may be that I don't understand your question but it seems that you already have the correct solution.
#3
08/05/2011 (1:47 pm)
Hey any solution to this?...

If I use the same code, I get all my fields erased except for the ones I am writing.

Any solutions?
#4
08/05/2011 (1:57 pm)
@Alebrije Estudios, I'm not an expert, but it seems to me you just have the code write everything each time they save. It ensures that everything but the values stay the same, and that ALL new data that you save is saved.
#5
08/05/2011 (2:08 pm)
@Laura Hill, thanks. I wanted to avoid to do that.