Scripting:Read Settings
From TSWiki
[edit] How To Read Your Own XML Settings File
[edit] Introduction
So you want to know how to read 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 write to an XML file
[edit] Example Script
#We include the .NET Forms and XML libraries.
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 XmlTextReader, WhitespaceHandling, Read, and ReadInnerXML, but I was too lazy.
from System.Xml import *
#We need to use a message box in this example so in it goes.
from System.Windows.Forms import MessageBox
#Read in your xml file.
Reader = XmlTextReader(AppSettings.GetInstance().AppSettingsPath + "\\titles.xml")
#Remove whitespaces around the values you read in.
Reader.WhitespaceHandling = WhitespaceHandling.None
#Set our beginning value for our loop.
Continue = True
#If our first read is bad then no reason to loop.
if(Reader.Read == False):
Continue = False
#loop through all the values looking for the one that is ours. In this case we display all the values with the name of our choice. In this case Title
while(Continue):
#If we are reading the start element section then let's do some checking.
if(Reader.IsStartElement):
#If the element we are currently reading has the name of title then we want that value.
if(Reader.Name == "title"):
#Display a messagebox showing us the value of that title.
MessageBox.Show(Reader.ReadInnerXml())
#If the element is not the name we are looking for keep on looking.
else:
Continue = Reader.Read()
#If we aren't in the start element section then keep looking for it.
else:
Continue = Reader.Read()
