4
votes

When referencing definitions in another XSD, we use "import" for another XSD that is in different namespace, and use "include" for another XSD that is in the same namespace.

That said, we don't need to import xmlns:xsd="http://www.w3.org/2001/XMLSchema before using it. Why? I wonder how is the XSD schema made available to the application---which file contains this XSD? Is it because it is already in application's classpath?

Similarly, I wonder if we need to do import or include if the other schema we created will be in application's classpath?

1

1 Answers

2
votes

The xmlns:xsd="http://www.w3.org/2001/XMLSchema namespace declaration associates the xsd namespace prefix with the http://www.w3.org/2001/XMLSchema namespace URI. This special namespace defines the vocabulary used in XML Schema; it is not associated with user XSDs brought in via xsd:import and xsd:include.

Related: There is an XML Schema schema v1.0 (or v1.1), which can be used to validate XSDs, but XSD processors can have their own validation methods and do not necessarily have to read in the XML Schema schema.

Also related: The xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance declaration associates xsi with the http://www.w3.org/2001/XMLSchema-instance namespace and is for several attributes defined by the XML specification: xsi:type, xsi:nil, xsi:schemaLocation, and xsi:noNamespaceSchemaLocation

None of these require importing or including by the user.

Yes, an XSD has to explicitly import or include all other XSDs containing needed components; there is no automatic importing or including of these XSDs associated with any sort of classpath.