C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

XML READ / WRITE in ASP.net


Posted Date: 01 Oct 2007    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: KamalMember Level: Gold    
Rating: 1 out of 5Points: 12



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();



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Save Changes on Close of Browser or when exiting the page.
Previous Resource: New in ADO.Net 2.0 - DataView.ToTable()
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use