Alright I'm having some problems reading an XML file. The method I wrote seems to just stop after a very specific line (when stepping through it just stops after it has executed that line even though there's more code after it).
XML:
<?xml version="1.0" encoding="utf-8"?>
<Timers>
<Timer title="Test" x="998" y="197" width="500" height="83" opacity="1" ontop="False">
<Year>2013</Year>
<Day>29</Day>
<Hour>12</Hour>
<Minute>19</Minute>
<Second>25</Second>
<Millisecond>101</Millisecond>
<Note />
</Timer>
</Timers>
Method:
public bool LoadTimers()
{
if (File.Exists(Path.GetDirectoryName(Application.ExecutablePath) + "\\data.pts"))
{
bool foundTimer = false;
XmlDocument doc = new XmlDocument();
doc.Load(Path.GetDirectoryName(Application.ExecutablePath) + "\\data.pts");
foreach (XmlNode node in doc.DocumentElement)
{
if (node.NodeType == XmlNodeType.Element && node.Name == "Timer")
{
//Create a new timer.
Form1 form = new Form1(this);
form.Show();
form.TimerName = node.Attributes["title"].Value.ToString();
form.Left = int.Parse(node.Attributes["x"].Value.ToString());
form.Top = int.Parse(node.Attributes["y"].Value.ToString());
form.Width = int.Parse(node.Attributes["width"].Value.ToString());
form.Height = int.Parse(node.Attributes["height"].Value.ToString());
form.Opacity = double.Parse(node.Attributes["opacity"].Value.ToString());
form.TopMost = bool.Parse(node.Attributes["ontop"].Value.ToString());
//Date.
int year = 0, day = 0, hour = 0, minute = 0, second = 0, millisecond = 0;
string note = "";
foreach (XmlNode dateNode in node.ChildNodes)
{
if (dateNode.NodeType == XmlNodeType.Element)
{
if (dateNode.Name == "Year") year = int.Parse(dateNode.Value);
if (dateNode.Name == "Day") day = int.Parse(dateNode.Value);
if (dateNode.Name == "Hour") hour = int.Parse(dateNode.Value);
if (dateNode.Name == "Minute") minute = int.Parse(dateNode.Value);
if (dateNode.Name == "Second") second = int.Parse(dateNode.Value);
if (dateNode.Name == "Millisecond") millisecond = int.Parse(dateNode.Value);
if (dateNode.Name == "Note") note = dateNode.Value;
}
}
foundTimer = true;
}
}
return foundTimer;
}
return false;
}
The line it just stops at is this:
if (dateNode.Name == "Year") year = int.Parse(dateNode.Value);
The if statement is true and it does execute "year = int.Parse(dateNode.Value);" but it doesn't continue from there. It just stops executing the method.