I’ve been messing around with XML validation via xsd but I’m still newbie. I try validate this xml and it pops me this error: cvc-elt.1: Cannot find the declaration of element ‘customers’. [5]
<?xml version="1.0"?>
<customers xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://w3schools.com requested_customer.xsd">
<customer name="Vladimir Putin" address="St. Petersburg, wadim street 23, Russia"/>
</customers>
and the XSD
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xs:element name="customers">
<xs:complexType>
<xs:sequence>
<xs:element name="customer">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="address"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Thanks for your help!
First thing first, your XML doesn’t uses XML namespaces for its content, so to reference an XSD’s file location without a target namespace you should use the xsi:noNamespaceSchemaLocation attribute instead.
Secondly, you have to make sure that the location of the XSD file is known to, and accessible by, the validating program.
Your XML/XSD combo is perfectly valid.