Q:

Identyfing the namespace of an inner XML element

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.

A:

According to §6.2 Namespace Defaulting of Namespaces in XML 1.0 (Third Edition):

The scope of a default namespace declaration extends from the beginning of the start-tag in which it appears to the end of the corresponding end-tag, excluding the scope of any inner default namespace declarations. […]
A default namespace declaration applies to all unprefixed element names within its scope.

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:
<element xmlns="namespace-uri">

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:
XDocument doc = …;

var ns = doc.Root.GetDefaultNamespace();

var newElement = new XElement(ns + "foo"));

