Understanding elementFormDefault qualified/unqualified when validating xml against a WSDL (xsd schema)

Felix Schwarz picture Felix Schwarz · Nov 13, 2013 · Viewed 22.8k times · Source

I'm trying to understand the implications of elementFormDefault="qualified/unqualified" in an XML schema which is embedded in WSDL (SOAP 1.1, WSDL 1).

For example I have this schema inside a WSDL:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified"
    targetNamespace="http://www.example.com/library">
    <xsd:element name="person">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="name" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

In plain XML this is obviously invalid because "name" has no specified namespace:

<lib:person xmlns:lib="http://www.example.com/library">
    <name>XML Schema</name>
</lib:person>

while this is obviously valid because all elements are qualified:

<lib:person xmlns:lib="http://www.example.com/library">
    <lib:name>qualified xml</lib:name>
</lib:person>

But surprisingly libxml says that the following is also valid:

<person xmlns="http://www.example.com/library">
    <name>XML Schema</name>
</person>

Question 1: I assumed that qualified meant <person> should look something like <lib:person xmlns:lib="...">. But the results seem to indicate that the xmlns attribute does the same?

Now assume that the above XML is part of a SOAP request, e.g.

...
<s:Body>
    <person xmlns="http://www.example.com/library">
        <name>XML Schema</name>
    </person>
</s:Body>
...

Question 2: Is the request above valid if the WSDL contains a qualified schema as displayed above? (plain SOAP, disregarding WS-I basic profile)

Question 3 When I consider WS-I Basic profile (especially 4.1.13 SOAP Body and Namespaces) is the above request still valid? (is person considered "namespace qualified"?)

Answer

Michael Kay picture Michael Kay · Nov 13, 2013

Specifying "qualified" in the schema, which is nearly always the right thing to do, means that local element declarations (xs:element within xs:complexType) refers to elements in the target namespace of the schema. Without it, they refer to elements in no namespace.

So with qualified, in your case, the name element must be in the namespace http://www.example.com/library. It will be in this namespace if either

(a) you explicitly put it in this namespace, as in this example:

<lib:person xmlns:lib="http://www.example.com/library">
    <lib:name>qualified xml</lib:name>
</lib:person>

(b) or you use a default namespace, as in this example:

<person xmlns="http://www.example.com/library">
    <name>qualified xml</name>
</person>