Use System.Xml class for Xml Reading/writing
Use XmlTextReader for xml reading and XmlTextWriter for xml writing.
XmlReader : Fast,read-only and Forward only cursor for processing xml documents Xml Writer : Alows to produce xml documents with W3C's XML 1.0 + Namespaces Rcommendations
Read The XML File: ---------------------------
private void Button2_Click(object sender, System.EventArgs e) { XmlTextReader reader = new XmlTextReader(Server.MapPath("CDCatalog.xml"));
reader.WhitespaceHandling = WhitespaceHandling.None; XmlDocument xmlDoc = new XmlDocument(); //Load the file into the XmlDocument xmlDoc.Load(reader); // reader.Close(); //Add and item representing the document to the listbox ListBox1.Items.Add("XML Document"); //Find the root node, and add it togather with its childeren XmlNode xnod = xmlDoc.DocumentElement; AddWithChildren(xnod,1); }
Write XML File:: ---------------------
Creates XML file
XmlTextWriter myXMLFileWriter = new XmlTextWriter(@"D:\Viv_B-Practice\BestPractice\myXMLfile.xml", null); myXMLFileWriter.WriteStartDocument(); myXMLFileWriter.WriteComment("Comment For my XML File"); //myXMLFileWriter.WriteElementString("Name", "Abdul Kalam"); myXMLFileWriter.WriteStartElement("Name"); myXMLFileWriter.WriteStartElement("FirstName"); myXMLFileWriter.WriteString("APJ Abdul"); myXMLFileWriter.WriteEndElement(); myXMLFileWriter.WriteStartElement("LastName"); myXMLFileWriter.WriteString("Kalam"); myXMLFileWriter.WriteEndDocument(); myXMLFileWriter.Close();
|
No responses found. Be the first to respond and make money from revenue sharing program.
|