Suppose I have such elements in my XML document:
<xs:appinfo>
<CustomXML>
<Something>something</Something>
</CustomXML>
</xs:appinfo>
“xs” is declared as the default schema namespace. My question is: how would a parser interpret the inner elements of xs:appinfo? In which namespace do they belong?
I ask because I’m parsing the code in C# and it keeps adding “xmlns=”” ” to the CustomXML element, which makes me assume that otherwise it’d treat these elements as schema elements.
According to §6.2 Namespace Defaulting of Namespaces in XML 1.0 (Third Edition):
That means that elements with no namespace prefix are interpreted as being in the default namespace. Default namespace is usually defined on the first element of the document and look like this:
The library redefines the default namespace when it’s necessary, that is, when you add an element to the document with no namespace. In other words, such element is not in the default namespace, so the library solves this by adding
xmlns=""to that element, which redefined the default namespace for this element and all its descendants to "no namespace".If you want to add element that is in the default namespace, you have to specify it explicitly. For example, in LINQ to XML: