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 !




Reading an XML File


Posted Date: 03 Mar 2007    Resource Type: Code Snippets    Category: XML

Posted By: Mathews . T. Varghese       Member Level: Gold
Rating:     Points: 10



The following c# code shows how to read from an xml file

Using the XmlTextReader class you get a forward only stream of XML data. It is then possible to handle each element as you read it without holding the entire DOM in memory.



First Element
Second Element
Third Element
Fourth Element
Fifth Element


It is assumed that the XML File shown above is in your applications Bin\Debug directory, and called xmlfile.xml, here is the C# Code to read the XML:

string filename = "xmlfile.xml";

XmlTextReader tr = new XmlTextReader(filename);

while(tr.Read())
{
if(tr.NodeType == XmlNodeType.Text)
System.Console.WriteLine(tr.Value);
}

When you run this example, you will get the following result:

First Element
Second Element
Third Element
Fourth Element
Fifth Element




Responses


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

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Authenticating Users Using an XML File  .  

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: Creating an XML Document
Previous Resource: Encrypt data in XML file
Return to Discussion Resource Index
Post New Resource
Category: XML


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

fax server

Contact Us    Privacy Policy    Terms Of Use