验证错误[IDREF没有ID / IDREF绑定]

时间:2010-09-20 07:35:57

标签: validation xsd

我在根据Schema验证XML文件时收到此错误消息。任何人都可以建议可能出错的地方? XML文件是:

<?xml version="1.0"?>
<family-tree xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ftree.xsd">

<person id="p5">
<name>
<given>Al Frank</given>
<surname>Smith</surname>
</name>
</person>

<person id="p6">
<name>
<given>Henry</given>
<surname>Smith</surname>
</name>
<father ref="p5"/>
</person>

</family-tree>

架构是:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

<xsd:element name="family-tree">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="person" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="person">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="father" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="id" use="required" type="xsd:ID"/>
</xsd:complexType>
</xsd:element>

<xsd:element name="name">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="0" name="given"/>
<xsd:element minOccurs="0" name="surname"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="given" type="xsd:string"/>
<xsd:element name="surname" type="xsd:string"/>

<xsd:element name="father">
<xsd:complexType>
<xsd:attribute name="ref" use="required" type="xsd:IDREF"/>
</xsd:complexType>
</xsd:element>

</xsd:schema>

1 个答案:

答案 0 :(得分:0)

您使用的是哪种XML解析器?也许你的解析器不喜欢你的文件中没有引用任何id的事实。但是,我不记得读到这样的要求。也许在XML声明中添加standalone =“no”(&lt;?xml version =“1.0”standalone =“no”?&gt;)会有帮助吗?