I have some XML files to parse, some of them are like this:
<?xml version="1.0" encoding="UTF-8"?>
<ab:rootNode xmlns:ab="http://www.uri.com">
<ab:nodeDate>...</ab:nodeDate>
</ab:rootNode>
and other of them are without namespace:
<?xml version="1.0" encoding="UTF-8"?>
<rootNode>
<nodeDate>...</nodeDate>
</node>
In LINQ to XML, I should to precise the namespace otherwise it don't fine any nodes.
How to manage namespaces? Do I test if xmlns:ab="http://www.uri.com"
exist in the rootNode
element? and if it exists I create a XNamespace
and add it to the name element like this (pseudo code):
XNamespace ab = "http://www.uri.com";
string prefixe = String.Empty;
if (XmlNamespaceExists(ab , "rootNode")
{
prefixe = ab;
}