加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xsd – 使用xs:all扩展XML Schema类型有什么问题?

发布时间:2020-12-16 22:53:33 所属栏目:百科 来源:网络整理
导读:?xml version="1.0" encoding="utf-8"?xs:schema xmlns="http://tempuri.org/ServiceDescription.xsd" xmlns:mstns="http://tempuri.org/ServiceDescription.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://tempuri.org/Service
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns="http://tempuri.org/ServiceDescription.xsd" xmlns:mstns="http://tempuri.org/ServiceDescription.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://tempuri.org/ServiceDescription.xsd" elementFormDefault="qualified" id="ServiceDescription">
    <xs:element name="Template">
        <xs:complexType>
            <xs:complexContent>                                     
                <xs:extension base="ServiceType">
                    <xs:all>
                        <xs:element name="TemplateCode" type="xs:string"/>
                    </xs:all>
                </xs:extension>
            </xs:complexContent>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="ServiceType">
        <xs:all>
            <xs:element name="ServiceCode" type="xs:string"/>
        </xs:all>
    </xs:complexType>
</xs:schema>

当我尝试在XMLSpy中保存它时,它告诉我

An ‘all’ model group is neither allowed in complex type definition ‘mstns:ServiceType’ nor in its extension ‘{anonymous}’.

单击“详细信息”会显示指向a paragraph in XML Schema specification的链接,我不明白.

补充:啊,是的,忘了提 – 错误的行是这一行:

<xs:element name="TemplateCode" type="xs:string"/>

解决方法

问题是,如果你扩展另一种类型,你不能拥有所有.就XML而言,父类型可能具有序列模型,并且由于XML禁止将所有组放入序列组(因为这会破坏序列组的排序),因此XML也禁止将所有组放入复合体的扩展中类型.虽然你可以使用序列而不是全部,但你会没事的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读