You ignore the XML namespace that fits into serialized XML:
<Person xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.datacontract.org/2004/07/DataContractLibrary">
<Age>34</Age>
<FirstName>SomeFirstName</FirstName>
<LastName>SomeLastName</LastName>
</Person>
So, in your code, you need to reference this namespace:
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(document.NameTable);
namespaceManager.AddNamespace("ns", document.DocumentElement.NamespaceURI);
XPath, :
XmlNode firstName = document.SelectSingleNode("//ns:FirstName", namespaceManager);
if (firstName == null)
{
Console.WriteLine("Could not find the node.");
}
else
{
Console.WriteLine("First Name is: {0}", firstName.InnerText);
}
- .