首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Server模式集合中的可重用simpleType定义

Server模式集合中的可重用simpleType定义
EN

Stack Overflow用户
提问于 2020-06-02 21:53:17
回答 1查看 58关注 0票数 1

我试图在Server模式集合中创建一个可重用的simpleType,但是我得到了一个错误。例如:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-16"?>
<xs:schema
    attributeFormDefault="unqualified"
    elementFormDefault="qualified"
    targetNamespace="SomethingUnique"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:simpleType name="dateTimeOrEmpty">
        <xs:union memberTypes="xs:dateTime">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value=""/>
                </xs:restriction>
            </xs:simpleType>
        </xs:union>
    </xs:simpleType>

    <xs:element name="Root">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="SomeDate"/>
                    <xs:simpleType>
                        <xs:union memberTypes="xs:dateTime">
                            <xs:simpleType>
                                <xs:restriction base="xs:string">
                                    <xs:enumeration value=""/>
                                </xs:restriction>
                            </xs:simpleType>
                        </xs:union>
                    </xs:simpleType>
                <xs:element name="OtherDate" type="dateTimeOrEmpty" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

如果我尝试使用此模式创建XML模式集合,则会得到以下错误

引用未定义的名称“dateTimeOrEmpty”

是否可以重用命名的simpleType定义,或者是否必须为要使用它的每个元素重新键入整个simpleType定义?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-02 22:23:26

看起来是命名空间问题。我想我曾经理解过这一点,但现在我不得不摆弄它,直到它起作用。例如

代码语言:javascript
复制
CREATE XML SCHEMA COLLECTION foo AS  
N'<?xml version="1.0" encoding="UTF-16"?>
<xs:schema
    attributeFormDefault="unqualified"
    elementFormDefault="qualified"
    targetNamespace="SomethingUnique"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:s="SomethingUnique"
    >

    <xs:simpleType name="dateTimeOrEmpty">
        <xs:union memberTypes="xs:dateTime">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value=""/>
                </xs:restriction>
            </xs:simpleType>
        </xs:union>
    </xs:simpleType>

    <xs:complexType name="RootType">
        <xs:sequence>
                <xs:element name="SomeDate" type="s:dateTimeOrEmpty"/>
                <xs:element name="OtherDate" type="s:dateTimeOrEmpty" />
            </xs:sequence>
    </xs:complexType>

    <xs:element name="Root" type="s:RootType"/>

</xs:schema>'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62161975

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档