I'm attempting to read an XML file with a namespace defined on the root element.
I've read several articles that suggest using XReader, using XmlNamespaceManager, stripping out the namespace with RegEx, etc.
What is the "best practices" way of reading the Title element from the following XML:
<foo xmlns="http://company.com/markup">
<bar>
<title>THIS IS MY TEST TITLE</title>
</bar>
</foo>
The following code works only if I remove the namespace from the foo element:
// Omitted checking for nulls for brevity.
var doc = XDocument.Load(fi.FullName);
var vFoo = doc.Element("foo");
var vBar = vFoo.Element("bar");
var vTitle = vFoo.Element("title");
When I attempt to use the XName.Get method with the namespace, that fails to return the root element.
// Omitted checking for nulls for brevity.
var doc = XDocument.Load(fi.FullName);
// FOLLOWING FAILS TO RETURN ELEMENT DESPITE EXPLICITLY INCLUDING NAMESPACE NAME
var vFoo = doc.Element(XName.Get("foo", "http://company.com/markup"));
var vBar = vFoo.Element("bar");
var vTitle = vFoo.Element("title");