Reading xml attributes in C#

SheoNarayan
Posted by SheoNarayan under C# category on | Views : 9787
To read xml attribute in C#, use following code snippets.

private void ReadXML()
{
StringBuilder strB = new StringBuilder("", 500);
XmlReader reader = new XmlTextReader("myfund.xml");
try
{
while (reader.ReadToFollowing("rect"))
{
strB.Append("z: " + reader.GetAttribute("z").ToString());
strB.Append(" | Y: " + reader.GetAttribute("y").ToString());
strB.Append(" | style: " + reader.GetAttribute("style").ToString());
strB.Append("<hr />");
}
}
catch
{
throw;
}
finally
{
reader.Close();
}
Response.Write(strB.ToString());
}


Assuming you have rect as the parent node and z, y and style as attributes.

Comments or Responses

Login to post response