I have the following XML file
<?xml version="1.0" ?>
<Persons>
<Person>
<Id>1</Id>
<Name>temp</Name>
<Qlid>1234</Qlid>
<Manager>3</Manager>
</Person>
<Person>
<Id>2</Id>
<Name>someone</Name>
<Qlid>5678</Qlid>
<Manager>1</Manager>
</Person>
</Persons>
I am trying to read it in using the following c# function
protected void readXmlFile()
{
FileStream fs = new FileStream("C:/Documents and Settings/me/Desktop/chart.xml",FileMode.Open);
XmlTextReader r = new XmlTextReader(fs);
//debug
StringWriter st = new StringWriter();
List<Person> persons = new List<Person>();
//Loop through persons in XML
while (r.Read())
{
if (r.NodeType == XmlNodeType.Element && r.Name == "Person")
{
Person newPerson = new Person();
while (r.NodeType != XmlNodeType.EndElement)
{
r.Read();
if (r.Name == "Id")
{
st.Write("67");
while (r.NodeType != XmlNodeType.EndElement)
{
r.Read();
if (r.NodeType == XmlNodeType.Text)
{
newPerson.Id = Int32.Parse(r.Value);
st.Write(r.Value);
}
}
}
r.Read();
if (r.Name == "Name")
{
while (r.NodeType != XmlNodeType.EndElement)
{
r.Read();
if (r.NodeType == XmlNodeType.Text)
{
newPerson.Name = (r.Value);
st.Write("23");
}
}
}
r.Read();
if (r.Name == "Qlid")
{
while (r.NodeType != XmlNodeType.EndElement)
{
r.Read();
if (r.NodeType == XmlNodeType.Text)
{
newPerson.Qlid = (r.Value);
st.Write(r.Value);
}
}
}
r.Read();
if (r.Name == "Manager")
{
while (r.NodeType != XmlNodeType.EndElement)
{
r.Read();
if (r.NodeType == XmlNodeType.Text)
{
newPerson.Manager = Int32.Parse(r.Value);
st.Write(r.Value);
}
}
}
//add to list
persons.Add(newPerson);
st.Write(90);
}
}
}
fs.Close();
the if(r.Name="Id") and similar ifs are never becoming true for some reason, returning empty person classes