Newbie:
I am writing code to read an xml file. I want two values from the document
so I want to save them as I am reading through the elements. I want to
reference them (using Console.WriteLine) after I complete the loop. When I
compile I get the "use of unassigned local variable".
What am I doing wrong?
stripped down code:
static void Main()
{
string Msg;
try
{
// Open an XML file
XmlTextReader reader = new XmlTextReader("...");
while ( reader.Read() )
{
if (reader.NodeType == XmlNodeType.Whitespace)
continue;
if (reader.NodeType != XmlNodeType.EndElement )
{
Msg = reader.Value;
}
if (reader.HasAttributes)
{
reader.MoveToFirstAttribute();
}
}
}
catch (Exception e)
{
Console.WriteLine ("Exception: {0}", e.ToString());
}
Console.WriteLine(Msg);
}