C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




XML READ / WRITE in ASP.net


Posted Date: 01 Oct 2007    Resource Type: Articles    Category: Web Applications

Posted By: Kamal       Member Level: Gold
Rating:     Points: 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  
(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: Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

internet fax

Contact Us    Privacy Policy    Terms Of Use