Simple XML Read & Write

  • 2931
  • 0
  • 2011-03-30

Simple XML Read & Write

Read

			   1: XmlDocument XDoc= new XmlDocument(); 
			   2: XmlTextReader XReader = new 
			   3: XmlTextReader(Server.MapPath("~/Order.xml")); 
			   4: XDoc.Load(XReader);
			   5: txtMax.Text = XDoc.SelectSingleNode("/Orders/Order").InnerText;
			   6: XReader.Close();

Write

			   1: XmlWriter writer = XmlWriter.Create(Server.MapPath("~/Order.xml")); 
			   2:  
			   3: writer.WriteStartDocument(); 
			   4: writer.WriteStartElement("Orders"); 
			   5:  
			   6: writer.WriteElementString("Order", "200"); 
			   7: writer.WriteEndElement(); 
			   8:  
			   9: writer.WriteEndDocument(); 
			  10: writer.Flush();