XML validation: why is explicitly specifying a namespace not allowed in this case?

191 views Asked by At

Given the following XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:foo="urn:foo" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            targetNamespace="urn:foo" 
            version="3.0">
  <xsd:complexType name="Something">
    <xsd:sequence>
      <xsd:element name="Nested" type="foo:NestedType"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="NestedType" />
</xsd:schema>

The following XML is valid:

<ns:Something xmlns:ns="urn:foo" 
              xsi:type="ns:Something" 
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Nested />
</ns:Something>

while this XML (only difference: 'Nested' is explicitly namespaced) isn't:

<ns:Something xmlns:ns="urn:foo" 
              xsi:type="ns:Something" 
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ns:Nested />
</ns:Something>

(at least according to the validator at http://www.utilities-online.info/xsdvalidation/).

Why am I not allowed to specify the namespace on that Nested element? Wouldn't I only be more explicit than strictly necessary?

1

There are 1 answers

1
potame On BEST ANSWER

It is because it in the XSD you have defined, the elementFormDefault is implicitely set to "unqualified".

Thus you can't set a namespace prefix to your elements.