Reading Data from XML

Posted: October 10, 2008 in XML

public string GetElementValue(string strElementName)
{
reader = new XmlTextReader(@”C:\Inetpub\wwwroot\NumberVerfication\NumberVerification.xml”);
Boolean flag = false;
string strElementValue = String.Empty;
while (reader.Read())
{
if (reader.LocalName == strElementName)
{
reader.Read();
strElementValue = reader.Value;
reader.Read();
flag = true;
}
}
if (flag == false)
{
return null;
}
else
return strElementValue;
}

Here i/p for themethod strElementName is the tag name in the xml for which the value has to be read.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s