你應該回去使用type="xsd:ID"
。除了確保值的唯一性之外,它還可以使您使用xsd:IDREF
進行參考。
當您嘗試使用xsd:ID
時出現的錯誤是ID值必須以字母開頭。如果您將您的ID更改爲「ID-1」/「ID-2」或「a1」/「a2」之類的東西,它就會正常工作。
示例模式:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xsd:element name="doc">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" ref="a"/>
<xsd:element maxOccurs="unbounded" ref="b"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="a">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="id" use="required" type="xsd:ID"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="b">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="idref" use="required" type="xsd:IDREF"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>
示例XML:
<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Untitled1.xsd">
<a id="ID-1">
...........
</a>
<a id="ID-2">
............
</a>
<b idref="ID-1"/>
</doc>
因此,如果您指定的XSD你沒有得到一個錯誤,但是如果你不指定一個你怎麼辦? – kjosh 2012-03-26 17:48:16