Scripting:Write Settings
From TSWiki
[edit] How To Write To Your Own XML Settings File
[edit] Introduction
So you want to know how to write your own XML Settings File. Well the example code here shows exactly how it's done. Basic example, but most settings files are pretty basic.
Find out how to read an xml file.
[edit] Example Script
#We include the .NET Forms and XML libraries. Forms may not be necessary.
clr.AddReferenceByPartialName("System.Windows.Forms")
clr.AddReferenceByPartialName("System.Xml")
#We then bring in the classes
#This takes us to the application settings directory for PHPCoder,Webcoder etc.
from TSW.PhpCoder.Classes import AppSettings
#Bring in all the Xml classes. We could have limited it to XmlTextWriter, WriteStartElement, WriteElementString, WriteEndElement and close, but I was too lazy.
from System.Xml import *
#XmlTextWriter needs to get the Encoding Class from System.Text So we import that.
from System.Text import Encoding
#Open up our file for writing. Use a unique name so you don't collide with other files.
writer = XmlTextWriter(AppSettings.GetInstance().AppSettingsPath + "\\titles.xml",Encoding.UTF8)
#Write our Start Element
writer.WriteStartElement("items")
#Wrote the subelements
writer.WriteElementString("title", "Unreal Tournament 2003")
writer.WriteElementString("title", "C&C: Renegade")
writer.WriteElementString("title", "Dr. Seuss's ABC")
#Write our closing tag of our start element
writer.WriteEndElement()
#Close the file.
writer.Close()
