You have a schema with a target namespace and qualified elements (wich means you don't have to prefix your elements to apply target namespace):
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.exemple.com/my-namespace-URI"
xmlns="http://www.exemple.com/my-namespace-URI"
elementFormDefault="qualified">
<-- Your schema definition -->
</xs:schema>
You have to include it in your root element. First the xml-schema namespace:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
(from here the xsi:
prefix corresponds to this namespace)
Then reference the schemaLocation attribute
xsi:schemaLocation="http://www.exemple.com/my-namespace-URI my.xsd"
where my.xsd
is the location of the XSD file (by default relative to the XML document's location). You can put a complete URL like
xsi:schemaLocation="http://www.exemple.com/my-namespace-URI http://www.exemple.org/xml/my.xsd"
So that gives your document:
<?xml version="1.0"?>
<doc xmlns="http://www.exemple.com/my-namespace-URI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.exemple.com/my-namespace-URI http://www.exemple.org/xml/my.xsd">
<!-- Document content -->
</doc>
Note that the XSD file URL is not necessarily related to the namespace URI.