The following code works fine. See the XML file below.
XPathDocument xPathDoc = new XPathDocument(@"C:\Authors.xml");
XPathNavigator navigator = xPathDoc.CreateNavigator();
XPathNodeIterator iterator = navigator.Select("/Contacts/Author/FirstName");
iterator.MoveNext();
string firstName = iterator.Current.InnerXml;
Console.WriteLine(firstName);
The value of "firstName" returns "Joe", which is ideal. However, when I add this attribute xmlns = "http://www.w3.org/1999/xhtml" to the '' tag so that it looks like this:
<Author xmlns="http://www.w3.org/1999/xhtml">
then the code does not return the correct value ('Joe') Why then does the xmlns = "http://www.w3.org/1999/xhtml" attribute affect the code above and what am I missing to return the correct value?
Any help would be greatly appreciated.
Here is the xml file:
<?xml version="1.0" encoding="UTF-8" ?>
<Contacts>
<Author>
<FirstName>Joe</FirstName>
</Author>
<Teacher>
<FirstName>Larry</FirstName>
</Teacher>
<Painter>
<FirstName>Mary</FirstName>
</Painter>
</Contacts>
source
share