Mega Code Archive

 
Categories / C# Tutorial / XML
 

Write attribute value

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Xml; using System.Xml.XPath;     public class MainClass     {         public static void Main()         {             XmlDocument doc;             XPathNavigator editor;             XmlWriter writer;             doc = new System.Xml.XmlDocument();             doc.Load("pubs.xml");             editor = doc.CreateNavigator().SelectSingleNode("/pubs");             writer = editor.AppendChild();             writer.WriteStartElement("publishers");             writer.WriteAttributeString("pub_id", "1234");             writer.WriteAttributeString("pub_name", "A");             writer.WriteEndElement();             writer.Close();             doc.Save("output.xml");         }     }