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?
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.