Your XML document has a default namespace of
"http://tempuri.org/sdnList.xsd"
.
Unfortunately, the
System.Xml
classes don't support default namespaces. Instead, you'll need to use an
XmlNamespaceManager
to define an alias for the default namespace, and use that in your queries:
XmlNamespaceManager nsmgr = new XmlNamespaceManager(root.OwnerDocument.NameTable);
nsmgr.AddNamespace("d", root.NamespaceURI);
XmlNodeList nodes = root.SelectNodes("//d:sdnDetails", nsmgr);
foreach (XmlNode node in nodes)
{
XmlNode fnamexml = node.SelectSingleNode("d:firstName", nsmgr);
...
}
It's slightly easier with
LINQ to XML[
^]:
XNamespace ns = root.Name.Namespace;
IEnumerable<XElement> nodes = root.Descendants(ns + "sdnDetails");
foreach (XElement node in nodes)
{
XElement fnamexml = node.Element(ns + "firstName");
...
}