The following xml document and schema was boiled down from a much larger schema in which the problem occured first:
The xml document:
<f2b:Foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:f2b="http://www.outerfoospace.com/schemas/foo2bar" xsi:schemaLocation="http://www.outerfoospace.com/schemas/foo2bar f2b-0-0-0.xsd">
<f2b:Bar>text</f2b:Bar>
</f2b:Foo>
The schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:f2b="http://www.outerfoospace.com/schemas/foo2bar" targetNamespace="http://www.outerfoospace.com/schemas/foo2bar">
<xs:complexType name="T_Foo">
<xs:sequence>
<xs:element name="Bar" xmlns="f2b"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Foo" type="f2b:T_Foo"/>
</xs:schema>
When I validate the document against the schema, I get an error message on the <f2b:Bar>
-element saying that <f2b:Bar>
is not expected. To make the document valid I have to put the <Bar>
-element explicitly (!) into the 'null-namespace': <Bar xmlns="">
.
I don't see why a null-namespaced element should be expected. The schema defines a namespace for all elements and for the <Foo>
-element the f2b
-namespace is indeed expected by the validator. But even if I explicitly set the namespace in the <Bar>
-element definition like I did above, the validator still expects xmlns=""
for the Bar
-element.
I tried several variations of the schema and the document to find an answer with no luck - and I simply can't guess why the hell in this special case the null-namespace is expected.
Any hint appreciated ... ekke
Short answer: add elementFormDefault="qualified"
to the root xs:schema
tag of your schema.
Longer answer: by default, only top-level "global" element declarations take on the target namespace of the schema. "Local" element declarations inside a complex type are in no namespace. You can override this for one particular local element using the form
attribute on the xs:element
tag, or globally for all elements using elementFormDefault
on the xs:schema
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With