考虑以下模式:
<;?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”/>;
</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行的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”/>;
</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:限制>;
</xs:simpleType>;
<;xs:attribute name=“AttRef”type=“xs:integer”/>;
</xs:schema>;