Thursday, July 30, 2009

Create New Xml File And Update values of the attributs in that XMl File

Creating New XmlFile

XmlTextWriter xml_writer = new XmlTextWriter(Server.MapPath(path), null);
  xml_writer.WriteStartDocument();
  xml_writer.WriteRaw("");
  xml_writer.WriteStartElement("Login_Details");
  xml_writer.WriteEndElement();
  xml_writer.WriteEndDocument();
  xml_writer.Close();


For Updating Attributes Value OF Xml 

XmlDocument xml_Doc = new XmlDocument();

xml_Doc.Load(Server.MapPath(path));

   XmlNode xml_node = xml_Doc.SelectSingleNode("Login_Details");
   foreach (XmlNode node in xml_node)
  {
    if (node.Attributes[0].InnerText.ToString()=="Test")
  {
  node.Attributes[0].InnerText = "Text_Modified";
  }
  }
  xml_Doc.Save(Server.MapPath(path));

No comments: