Reputation: 10273
I am trying to learn how to use extensions in xml schema. I took this example (Example 2 from here: http://www.w3schools.com/schema/el_extension.asp)
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="employee" type="fullpersoninfo"/>
<xs:complexType name="personinfo">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="fullpersoninfo">
<xs:complexContent>
<xs:extension base="personinfo">
<xs:sequence>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
and made a demo xml data file:
<?xml version="1.0"?>
<personinfo>
<firstname>John</firstname>
<lastname>Doe</lastname>
</personinfo>
But when I try to validate it, I get:
xmllint --schema myschema.xsd data.xml
<?xml version="1.0"?>
<personinfo>
<firstname>John</firstname>
<lastname>Doe</lastname>
</personinfo>
data.xml:3: element personinfo: Schemas validity error : Element 'personinfo': No matching global declaration available for the validation root.
data.xml fails to validate
Can anyone explain what I am doing wrong?
Upvotes: 1
Views: 2011
Reputation: 122374
Your XML file has a root element named personinfo
but your schema doesn't contain a declaration for an element with that name. It contains a declaration of a type called personinfo
but the only element declaration is for employee
(of type fullpersoninfo
).
An example XML file that validates against the current schema would be something like
<?xml version="1.0"?>
<employee>
<firstname>John</firstname>
<lastname>Doe</lastname>
<address>5 Somewhere Street</address>
<city>Anytown</city>
<country>Australia</country>
</employee>
Upvotes: 1