XSDs are not imported into XML files. XSDs are imported or included into other XSD files.
XSDs can be associated with XML files. The most common mechanism for establishing that association is via hints conveyed through schemaLocation
and noNamespaceSchemaLocation
Example: noNamespaceSchemaLocation
In the following XML file, purchaseReport
is in no namespace, and the associated XSD can be found at http://www.example.com/ReportB.xsd
:
<purchaseReport
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.example.com/ReportB.xsd">
<!-- etc. -->
</purchaseReport>
Note that ReportB.xsd
will have no targetNamespace
.
Example: schemaLocation
In the following XML file, purchaseReport
is in the http://www.example.com/Report
namespace, and the associated XSD can be found at http://www.example.com/Report.xsd
:
<purchaseReport
xmlns="http://www.example.com/Report"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.com/ReportA
http://www.example.com/ReportA.xsd">
<!-- etc. -->
</purchaseReport>
Note that ReportA.xsd
will have a targetNamespace
equal to the namespace of this XML file (http://www.example.com/ReportA
).
In your particular case, the master XSD that imports the other XSDs would most likely itself have a namespace, so you would use the schemaLocation
mechanism in an XML file to hint as to the location of the master XSD that governs the XML file.