Cags
Well-known member
Over the last few days Ive been begining to believe that my PC is involved in an elaborate plot to finally push me over the edge and go insane.
Im writing an xml file with this code...
The xml file looks like this...
Im reading it in with this code...
This is the output from the messagebox...
Did I miss some logic behind the structure of xml? Any suggestions?
Im writing an xml file with this code...
C#:
XmlTextWriter writer = new XmlTextWriter(path, System.Text.Encoding.UTF8);
writer.WriteStartDocument();
writer.WriteStartElement("Settings");
writer.WriteElementString("Difficulty", Difficulty.ToString());
writer.WriteElementString("MyType", MyType.ToString());
writer.WriteElementString("AnimationType", AnimationType.ToString());
writer.WriteElementString("UserImagePath", UserImagePath.ToString());
writer.WriteElementString("InternalImagePath", InternalImagePath.ToString());
writer.WriteElementString("UserImage", UserImage.ToString());
writer.WriteElementString("DrawIndex", DrawIndex.ToString());
writer.WriteElementString("DrawGrid", DrawGrid.ToString());
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
Code:
<?xml version="1.0" encoding="utf-8" ?>
<Settings>
<Difficulty>Hard</Difficulty>
<MyType>Slide</MyType>
<AnimationType>None</AnimationType>
<InternalImagePath>Images.image1</InternalImagePath>
<UserImage>False</UserImage>
<DrawIndex>False</DrawIndex>
<DrawGrid>True</DrawGrid>
</Settings>
C#:
XmlTextReader reader = new XmlTextReader(path);
while(reader.Read())
{
System.Windows.Forms.MessageBox.Show(reader.NodeType.ToString() + "," + reader.LocalName);
if(reader.NodeType == XmlNodeType.Element)
{
if(reader.Name == "Difficulty")
{
string text = reader.ReadInnerXml();
System.Reflection.FieldInfo fi = typeof(PzlDifficulty).GetField(text);
Difficulty = (PzlDifficulty)fi.GetValue(null);
}
else if(reader.Name == "MyType")
{
string text = reader.ReadInnerXml();
System.Reflection.FieldInfo fi = typeof(PzlType).GetField(text);
MyType = (PzlType)fi.GetValue(null);
}
else if(reader.Name == "AnimationType")
{
string text = reader.ReadInnerXml();
System.Reflection.FieldInfo fi = typeof(Animate).GetField(text);
AnimationType = (Animate)fi.GetValue(null);
}
else if(reader.Name == "UserImagePath")
{
UserImagePath = reader.ReadInnerXml();
}
else if(reader.Name == "InternalImagePath")
{
InternalImagePath = reader.ReadInnerXml();
}
else if(reader.Name == "UserImage")
{
UserImage = bool.Parse(reader.ReadInnerXml());
}
else if(reader.Name == "DrawGrid")
{
DrawGrid = bool.Parse(reader.ReadInnerXml());
}
else if(reader.Name == "DrawIndex")
{
DrawIndex = bool.Parse(reader.ReadInnerXml());
}
}
}
reader.Close();
Code:
XmlDeclaration,xml
Element,Settings
Element,Difficulty
Text,
EndElement,MyType
Element,AnimationType
Element,InternalImagePath
Text,
EndElement,UserImage
Element,DrawIndex
Text,
EndElement,DrawGrid
EndElement,Settings