I have a console application that reads an XML file and outputs everything into a console.
I need to convert this application to output the data on an .aspx page.
This is the code
// Declare XmlTextReader.
XmlTextReader r = new XmlTextReader("../../persons.xml");
while (r.Read())
{
switch (r.NodeType)
{
case XmlNodeType.Element:
if (r.Name == "Persons")
{
Console.WriteLine("<table>");
Console.WriteLine(" <tr> <th>Name</th> <th>Gender</th> <th>Age</th> </tr>");
}
else if (r.Name == "Person")
{
Console.Write(" <tr> ");
}
else if (r.Name == "Name" ||
r.Name == "Gender" || r.Name == "Age")
{
Console.Write("<td>");
}
break;
case XmlNodeType.Text:
Console.Write(r.Value);
break;
case XmlNodeType.EndElement:
if (r.Name == "Persons")
{
Console.WriteLine("</table>\n");
}
else if (r.Name == "Person")
{
Console.Write("</tr>\n");
}
else if (r.Name == "Name" ||
r.Name == "Gender" || r.Name == "Age")
{
Console.Write(">/td> ");
}
break;
}
}
I found a lot of examples on how to read XML using ASP.NET but unfortunately i need to this the hard way.
you need to add a literal control on your .aspx page like this:
Then modify the code like so:
cheers