Twitter Feed Popout byInfofru

Writing XML File Dynamically

Hey Geeks,Writing xml file in .net application is quit general but I have noticed most of the people do this work in a loong and wrong (in my opinion) way. They write the xml file with the help of dataset which is more like a database...... Yes offcourse resource heavy. So let us make this operation quit simple and easy. consider the following XML Schema. We will write the same schema from our code to a local file.
XML Schema :
<?xml version=“1.0“ encoding=“utf-8“?><Items><Item><ItemId>3</ItemId><ProductName>Pine Apple</ProductName><Price>30 $</Price><Item><Items>
VB.net Code :
Dim XMLDoc As New XmlDocumentXMLDoc.Load(Server.MapPath("MyData.xml"))Dim XEle As XmlElement = XMLDoc.CreateElement("Item")Dim XTxt As XmlText'XMLDoc.DocumentElement.AppendChild(XEle)XEle = XMLDoc.CreateElement("ItemID")XTxt = XMLDoc.CreateTextNode("3")XMLDoc.DocumentElement.AppendChild(XEle)XMLDoc.DocumentElement.LastChild.AppendChild(XTxt)XEle = XMLDoc.CreateElement("ProductName")XTxt = XMLDoc.CreateTextNode("Meera")XMLDoc.DocumentElement.AppendChild(XEle)XMLDoc.DocumentElement.LastChild.AppendChild(XTxt)XEle = XMLDoc.CreateElement("Price")XTxt = XMLDoc.CreateTextNode("50 $")XMLDoc.DocumentElement.AppendChild(XEle)XMLDoc.DocumentElement.LastChild.AppendChild(XTxt)XMLDoc.Save(Server.MapPath("MyData.xml"))