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