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

狂风中的少年 提交于 2019-12-20 12:27:24

问题


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


回答1:


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>


来源:https://stackoverflow.com/questions/19954278/understanding-elementformdefault-qualified-unqualified-when-validating-xml-again

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!