14
votes

Where is the XSD schema definition file for the namespace "http://www.w3.org/2001/XMLSchema-instance"?

4

4 Answers

15
votes

Strange it may sound, but the XML schema for http://www.w3.org/2001/XMLSchema-instance namespace does exist and is found exactly by the very URL denoted by the namespace URI: http://www.w3.org/2001/XMLSchema-instance

For a proof, just open that link (URL) in an HTML browser (e.g. FireFox). You will probably see some HTML text, like: "XML Schema instance namespace ...". Then, save that 'HTML' as a file on your computer (e.g. File | Save Page As). When you look into this file, you will see that it is not HTML at all. Rather, it is a complete XML schema for that namespace!

Equally, you can import the http://www.w3.org/2001/XMLSchema-instance namespace into your own schema as the following:

<xs:import namespace="http://www.w3.org/2001/XMLSchema-instance"
           schemaLocation="http://www.w3.org/2001/XMLSchema-instance"/>

See also this question: Error while parsing xsd using xjc, which although sounds very differently, actually very much related to the same problem.

3
votes

Just to add fuel to the fire -- many XML tools have knowledge of http://www.w3.org/2001/XMLSchema-instance baked-in, so it looks like you never need the schema at all. In fact, you need the schema if you are using an XML tool that does not bake-in this knowledge.

3
votes

So is for that reason that we find actually always beginning of xml documents where there ins't xml-schema xsd declaration at all? For example like this:

<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jee="http://www.springframework.org/schema/jee" 
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 

         http://www.springframework.org/schema/jee 
         http://www.springframework.org/schema/jee/spring-jee-3.2.xsd 

         http://www.springframework.org/schema/util 
         http://www.springframework.org/schema/util/spring-util-3.2.xsd">
1
votes

Here is some updated information on this topic.

XSD 1.1 part 1 §2.7 states:

XML Schema Definition Language: Structures defines several attributes for direct use in any XML documents. These attributes are in the schema instance namespace (http://www.w3.org/2001/XMLSchema-instance) described in The Schema Instance Namespace (xsi) (§1.3.1.2) above. All schema processors must have appropriate attribute declarations for these attributes built in.

Further, §3.2.6.4 says:

The {target namespace} of an attribute declaration, whether local or top-level, must not match http://www.w3.org/2001/XMLSchema-instance (unless it is one of the four built-in declarations given in the next section). Note: This reinforces the special status of these attributes, so that they not only need not be declared to be allowed in instances, but in consequence of the rule just given must not be declared.

So, you can't declare attributes such as xsi:type or xsi:schemaLocation in a schema document, and therefore you can't import a schema document that attempts to declare such attributes.

This of course is XSD 1.1 and therefore doesn't directly constrain an XSD 1.0 processor. However, it's one of the many areas where XSD 1.1 issues guidance for cases where XSD 1.0 said nothing, and where different implementations went off in different directions.