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

参考和类型在XML模式有什么区别?

发布时间:2020-12-16 07:42:05 所属栏目:百科 来源:网络整理
导读:考虑以下模式: ?xml version="1.0" encoding="ISO-8859-1" ?xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xs:complexType name="Root" xs:sequence xs:element ref="Child" / xs:element name="Child2" type="Child" / /xs:sequence xs:attribut
考虑以下模式:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:complexType name="Root">
        <xs:sequence>
            <xs:element ref="Child" />
            <xs:element name="Child2" type="Child" />
        </xs:sequence>
        <xs:attribute ref="Att" />
        <xs:attribute name="Att2" type="Att" />
    </xs:complexType>

    <xs:complexType name="Child">
        <xs:attribute ref="Att" />
    </xs:complexType>

    <xs:attribute name="Att" type="xs:integer" />

</xs:schema>

第6行对“Child”的引用失败,而第7行的类型验证.对于属性,ref会在类型失败时成功.我正在想明白为什么

我对ref的理解是,它只是引用另一个元素,并指定您希望在该位置看到一个引用类型的实例(在定义中给出的名称).显然我错了,那么ref是什么意思呢?

使用ref =“..”,您将“粘贴”在另一个地方定义的现有元素/属性.使用type =“..”,您将一些结构(在complextype / simpletype中定义)分配给新的元素/属性.看看下面:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tst="test" targetNamespace="test">

    <xs:complexType name="Root">
        <xs:sequence>
            <xs:element ref="tst:Child" />
            <xs:element name="Child2" type="tst:ChildType" />
        </xs:sequence>
        <xs:attribute ref="tst:AttRef" />
        <xs:attribute name="Att2" type="tst:AttType" />
    </xs:complexType>

    <xs:complexType name="ChildType">
        <xs:attribute ref="tst:AttRef" />
    </xs:complexType>

    <xs:element name="Child">
    </xs:element>

    <xs:simpleType name="AttType">
        <xs:restriction base="xs:string">
            <xs:maxLength value="10" />
        </xs:restriction>
    </xs:simpleType>

    <xs:attribute name="AttRef" type="xs:integer" />

</xs:schema>

(编辑:李大同)

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

    推荐文章
      热点阅读