What's the difference between xsd:include and xsd:import?
What's the difference between xsd:include
and xsd:import
? When would you use one instead of the other, and when might it not matter?
Solution 1:
The fundamental difference between include
and import
is that you must use import
to refer to declarations or definitions that are in a different target namespace and you must use include
to refer to declarations or definitions that are (or will be) in the same target namespace.
Source: https://web.archive.org/web/20070804031046/http://xsd.stylusstudio.com/2002Jun/post08016.htm
Solution 2:
Use xsd:include to bring in an XSD from the same or no namespace.
Use xsd:import to bring in an XSD from a different namespace.
Solution 3:
Another difference is that <import>
allows importing by referring to another namespace. <include>
only allows importing by referring to a URI of intended include schema. That is definitely another difference than inter-intra namespace importing.
For example, the xml schema validator may already know the locations of all schemas by namespace already. Especially considering that referring to XML namespaces by URI may be problematic on different systems where classpath:// means nothing, or where http:// isn't allowed, or where some URI doesn't point to the same thing as it does on another system.
Code sample of valid and invalid imports and includes:
Valid:
<xsd:import namespace="some/name/space"/>
<xsd:import schemaLocation="classpath://mine.xsd"/>
<xsd:include schemaLocation="classpath://mine.xsd"/>
Invalid:
<xsd:include namespace="some/name/space"/>