在针对 WSDL(xsd 架构)验证 xml 时了解 elementFormDefault 限定/不限定 [英] Understanding elementFormDefault qualified/unqualified when validating xml against a WSDL (xsd schema)

查看:41
本文介绍了在针对 WSDL(xsd 架构)验证 xml 时了解 elementFormDefault 限定/不限定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解 elementFormDefault="qualified/unqualified" 在嵌入 WSDL(SOAP 1.1、WSDL 1)的 XML 模式中的含义.

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

例如,我在 WSDL 中有这个架构:

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>

在纯 XML 中这显然是无效的,因为name"没有指定的命名空间:

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>

但令人惊讶的是,libxml 表示以下内容也是有效的:

But surprisingly libxml says that the following is also valid:

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

问题 1:我认为 qualified 意味着 应该类似于 .但结果似乎表明 xmlns 属性也做了同样的事情?

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?

现在假设上述 XML 是 SOAP 请求的一部分,例如

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>
...

问题 2:如果 WSDL 包含如上所示的 qualified 模式,上述请求是否有效?(纯 SOAP,无视 WS-I 基本配置文件)

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

问题 3 当我考虑 WS-I 基本配置文件(尤其是 4.1.13 SOAP 主体和命名空间) 上述请求是否仍然有效?(person 是否被视为命名空间合格"?)

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

推荐答案

在模式中指定合格",这几乎总是正确的做法,意味着局部元素声明(xs:complexType 中的 xs:element)引用到架构目标命名空间中的元素.如果没有它,它们将引用没有命名空间的元素.

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.

因此,在您的情况下,name 元素必须位于名称空间 http://www.example 中.com/图书馆.如果

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) 你明确地把它放在这个命名空间中,如本例所示:

(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) 或者您使用默认命名空间,如本例所示:

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

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

这篇关于在针对 WSDL(xsd 架构)验证 xml 时了解 elementFormDefault 限定/不限定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆