Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"?)

like image 747
Felix Schwarz Avatar asked Nov 13 '13 12:11

Felix Schwarz


People also ask

What is qualified and unqualified in XML schema?

The declaration of a target namespace gives us the possibility of defining elements and attributes that belong to the target namespace (called "qualified") and elements and attributes that don't belong to any namespace (called "unqualified").

What is elementFormDefault qualified in XSD?

elementFormDefault="qualified" is used to control the usage of namespaces in XML instance documents (. xml file), rather than namespaces in the schema document itself (. xsd file). By specifying elementFormDefault="qualified" we enforce namespace declaration to be used in documents validated with this schema.

Which is used as a qualifier to represent the schema elements in XML?

The XML representation of schema components uses a vocabulary identified by the namespace name http://www.w3.org/2001/XMLSchema . For brevity, the text and examples in this specification use the prefix xs: to stand for this namespace; in practice, any prefix can be used.

What is targetNamespace in XSD file?

The targetNamespace declares a namespace for other xml and xsd documents to refer to this schema. The target prefix in this case refers to the same namespace and you would use it within this schema definition to reference other elements, attributes, types, etc.


1 Answers

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>
like image 181
Michael Kay Avatar answered Oct 19 '22 07:10

Michael Kay