Not able to figure out what is the problem with following code and data. It returns "NullReferenceException was unhandled"
Code:
XmlDocument doc = new XmlDocument();
doc.Load(Filename1);
XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
mgr.AddNamespace("temp","http://www.Rahiman.com");
string name1 = doc.SelectSingleNode("//temp:Company/temp:Businesscard[2]/temp:Name", mgr).
InnerText;
Console.WriteLine(name1);
Data File:
<?xml version="1.0" encoding="utf-8" ?>
<Company xmlns="http://www.Rahiman.com">
<![CDATA[This data file is created as part of 1st BizTalk example]]>
<Businesscard>
<name> Rahiman </name>
<Phone Category="Mobile">+91 900028xxxx</Phone>
<Phone Category="Land">+91 40-40020xxxx</Phone>
<Phone Category="Fax">+91 900028xxxx</Phone>
<Email>John@Yahoo.com</Email>
</Businesscard>
<Businesscard>
<name>Shaik </name>
<Phone Category="Mobile">+91 900028xxxx</Phone>
<Phone Category="Land">+91 40-40020xxxx</Phone>
<Phone Category="Fax">+91 900028xxxx</Phone>
<Email>John@Yahoo.com</Email>
</Businesscard>
</Company >
I have tried
string name1 = doc.DocumentElement.SelectSingleNode("//temp:Company/temp:Businesscard[2]/temp:Name", mgr).
InnerText;
as well
Thanks.