在XSD-to-xs:redefinite-xs:complexType元素中是否可能需要type属性?

在XSD-to-xs:redefinite-xs:complexType元素中是否可能需要type属性?,xsd,schema,complextype,xmlspy,redefine,Xsd,Schema,Complextype,Xmlspy,Redefine,目标: 创建一个XSD,其中模式中定义的每个xs:element都需要“type”属性 能够重新使用重新定义的http://www.w3.org/2001/XMLSchema在其他模式中强制所有已定义的xs:element需要“type”属性 例如,我希望以下内容在XSD中“无效”(例如在XMLSpy中) 鉴于以下内容是有效的: <xs:element name="SomeElement" type="abc:SomeType"/> 下面是一个模式示例,我试图重新定义以要求

目标:

  • 创建一个XSD,其中模式中定义的每个xs:element都需要“type”属性

  • 能够重新使用重新定义的
    http://www.w3.org/2001/XMLSchema
    在其他模式中强制所有已定义的xs:element需要“type”属性

  • 例如,我希望以下内容在XSD中“无效”(例如在XMLSpy中)

    
    
    鉴于以下内容是有效的:

    <xs:element name="SomeElement" type="abc:SomeType"/>
    
    
    
    下面是一个模式示例,我试图重新定义
    以要求“type”属性

    <?xml version="1.0"?>
    <!-- edited with XMLSpy v2013 (http://www.altova.com) -->
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
               targetNamespace="http://www.w3.org/2001/XMLSchema"
               elementFormDefault="qualified" attributeFormDefault="unqualified">
        <xs:redefine schemaLocation="http://www.w3.org/2001/XMLSchema.xsd">
            <xs:complexType name="element" abstract="true">
                <xs:complexContent>
                    <xs:restriction base="xs:element">
                        <xs:attribute name="type" use="required">
                            <xs:simpleType>
                                <xs:restriction base="xs:QName"/>
                            </xs:simpleType>
                        </xs:attribute>
                    </xs:restriction>
                </xs:complexContent>
            </xs:complexType>
            <xs:complexType name="topLevelElement">
                <xs:complexContent>
                    <xs:restriction base="xs:topLevelElement"/>
                </xs:complexContent>
            </xs:complexType>
            <xs:complexType name="localElement">
                <xs:complexContent>
                    <xs:restriction base="xs:localElement"/>
                </xs:complexContent>
            </xs:complexType>
            <xs:complexType name="narrowMaxMin">
                <xs:complexContent>
                    <xs:restriction base="xs:narrowMaxMin"/>
                </xs:complexContent>
            </xs:complexType>
        </xs:redefine>
        <xs:element name="SomeElement"/>
    </xs:schema>
    
    
    
    现在,该模式有一些有趣的方面,以及XMLSpy 2013(无service pack)中的一些奇怪行为:

  • 在“文本”视图中,尝试保存时,XMLSpy指示模式“无效”

  • 在“Schema”视图中,尝试保存时,XMLSpy指示该模式有效

  • 尝试在XMLSpy中创建示例XML文件将导致一个错误,指示架构无效

  • 架构中唯一无效的部分是
    ,因为它没有用“type”属性定义

  • <?xml version="1.0"?>
    <!-- edited with XMLSpy v2013 (http://www.altova.com) -->
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
               targetNamespace="http://www.w3.org/2001/XMLSchema"
               elementFormDefault="qualified" attributeFormDefault="unqualified">
        <xs:redefine schemaLocation="http://www.w3.org/2001/XMLSchema.xsd">
            <xs:complexType name="element" abstract="true">
                <xs:complexContent>
                    <xs:restriction base="xs:element">
                        <xs:attribute name="type" use="required">
                            <xs:simpleType>
                                <xs:restriction base="xs:QName"/>
                            </xs:simpleType>
                        </xs:attribute>
                    </xs:restriction>
                </xs:complexContent>
            </xs:complexType>
            <xs:complexType name="topLevelElement">
                <xs:complexContent>
                    <xs:restriction base="xs:topLevelElement"/>
                </xs:complexContent>
            </xs:complexType>
            <xs:complexType name="localElement">
                <xs:complexContent>
                    <xs:restriction base="xs:localElement"/>
                </xs:complexContent>
            </xs:complexType>
            <xs:complexType name="narrowMaxMin">
                <xs:complexContent>
                    <xs:restriction base="xs:narrowMaxMin"/>
                </xs:complexContent>
            </xs:complexType>
        </xs:redefine>
        <xs:element name="SomeElement"/>
    </xs:schema>
    
  • 发生的错误与重复声明有关;但目前正在尝试的是一种重新定义,而不是另一种声明

  • 问题:

  • 是否可以重新定义
    以要求“type”属性
  • 是否可以在具有不同“targetNamespace”的其他XSD中使用此重新定义的类型
  • 由于“XSD”是由W3C控制的W3CXML模式语言, 你不能在其中重新定义任何东西。 具体来说,您不能重新定义
    http://www.w3.org/2001/XMLSchema
    名称空间

    你怎么能?毕竟,无论你做什么, 您始终需要从正常的
    元素开始,该元素已在该命名空间中定义,“已定义”在这里意味着
    的任何可能内容也已定义。 这里不可能有某种自举! 那将是一种不同的语言。(尽管这的确是一个奇怪的想法——把它写下来并发送给W3C!)

    那么,您可以做的就是定义自己的XML模式语言(例如“XSDX”)。。。但是在不同的名称空间中,是的,您可以基于标准XSD。只需导入
    http://www.w3.org/2001/XMLSchema
    命名空间并重用其中定义的任何构造(即全局组件)。“XSDX”语言的用途是另一回事。。。(我想,你必须开发一些新的软件来使用它。)

    然而,我想,您的实际目标是验证XML模式 符合某些传统要求(例如关于“类型”属性)

    您可以通过开发某种额外的验证器来实现这一点

    或者,您可以替换(临时)
    http://www.w3.org/2001/XMLSchema
    模式中的字符串,URI表示扩展XML模式语言。 然后,任何标准软件都会认为它只是另一种XML,与XML无关 它需要任何验证或其他任何东西。但是,您的扩展的 XML模式语言——以某种(正常的)XML模式的形式——仍然是需要的