Given the following xml:
<root xmlns="http://tempuri.org/myxsd.xsd">
<node name="mynode" value="myvalue" />
</root>
And given the following code:
string file = "myfile.xml"; //Contains the xml from above
XDocument document = XDocument.Load(file);
XElement root = document.Element("root");
if (root == null)
{
throw new FormatException("Couldn't find root element 'parameters'.");
}
If the root element contains the xmlns attribute then the variable root is null. If I remove the xmlns attribute then root is NOT null.
Can anyone explain why this is?