Monday, April 21, 2008

Replacing xml attribute in two ways

<?xml version="1.0" encoding="utf-8" ?><bookstore> <books> <book genre="reference"> <title>World Atlas</title> </book> <book genre="reference"> <title>World Atlas</title> </book> </books></bookstore>

XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("test.xml"));
XmlElement root = xmldoc.DocumentElement;
XmlNodeList nodes = root.SelectNodes("books/book");
////////////////////////////////Replaceing Attribute value using xml///////////////////////////////
foreach (XmlNode xn in nodes)
{
xn.Attributes[0].Value = "NA";
}
////////////////////////////////Replaceing Attribute value using xml///////////////////////////////
foreach (XmlNode xn1 in nodes)
{
XmlNode dd = xn1.SelectSingleNode("@genre");
}