XML模式中的ref和type有什么区别?

考虑以下模式:

<?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”/gt;
<xs:element name=“Child2”type=“Child”/>
&lt/xs:sequence>
<xs:attribute ref=“Att”/>
<xs:attribute name=“Att2”type=“Att”/>
&lt/xs:complexType>
<xs:complexType name=“Child”>
<xs:attribute ref=“Att”/>
&lt/xs:complexType>
<xs:attribute name=“Att”type=“xs:integer”/>
&lt/xs:schema>

第6行的ref到“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”/>
&lt/xs:sequence>
<xs:attribute ref=“tst:AttRef”/>
<xs:attribute name=“Att2”type=“tst:AttType”/>
&lt/xs:complexType>
<xs:complexType name=“ChildType”>
<xs:attribute ref=“tst:AttRef”/>
&lt/xs:complexType>
<xs:element name=“Child”>
&lt/xs:element>
<xs:simpleType name=“AttType”>
<xs:restriction base=“xs:string”>
<xs:maxLength value=“10”/>
&lt/xs:限制>
&lt/xs:simpleType>
<xs:attribute name=“AttRef”type=“xs:integer”/>
&lt/xs:schema>

发表评论