views:

24

answers:

1

I am getting this error message when validating my XML file against its Schema. Can anyone suggest what might be wrong? The XML file is:

<?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>

The schema is:

<?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>
A: 

Which XML parser are you using? Perhaps your parser doesn't like the fact that you have an id that is not referenced anywhere in the document. However, I don't remember reading about such a requirement. Perhaps adding standalone="no" to the XML declaration (<?xml version="1.0" standalone="no"?>) will help?

Boris Kolpackov