Saturday, 19 January 2013 13:56

how to read from a xml file

Written by 
Rate this item
(0 votes)
suppose you have some data in the xml file as shown -

<?xml version="1.0" encoding="utf-8" ?>

if you want to read those data according to element
then following codes surely help you.there are many
ways to read from a xml file.this is a way to read -

string xmlURL = "";
reader = new XmlTextReader(xmlURL);
string elementName = "";

if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "system"))
while (reader.Read())
// when we find an element node,
// we remember its name
if (reader.NodeType == XmlNodeType.Element)
elementName = reader.Name;
// for text nodes...
if ((reader.NodeType == XmlNodeType.Text) && (reader.HasValue))
// we check what the name of the node was
switch (elementName)
case "version":
NewVersion = new Version(reader.Value);
case "url":
url = reader.Value;

Read 3477 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.