<ServerSettings> <property name="ServerPort" value="25000"/> <property name="ServerIsPublic" value="true"/> <property name="ServerName" value="My Game Host"/> <property name="ServerPassword" value=""/> <property name="ServerMaxPlayerCount" value="4"/> </ServerSettings>
using (XmlReader prereader = XmlReader.Create(presetlocation)) // This variable is declared after selecting the xml preset file with OpenFileDialog // { while (prereader.Read()) { if (prereader.IsStartElement()) { switch (prereader.Name) { case "ServerSettings": break; case "property": string attribute = prereader["name"]; string attribute2 = prereader["value"]; if (attribute != null) { // This was writing the data to a txt to test the reading. It came up with strange results // FileStream fs1 = new FileStream("D:\\TEST.txt", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter writer = new StreamWriter(fs1); writer.Write(attribute + " " + attribute2); writer.Close(); } break; } } } }
if (attribute != null)
if (attribute == "ServerPort")
System.Xml.XmlDocument
System.Xml.XmlTextReader
System.Xml.Linq.XDocument
XmlDocument
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)