16

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

Mark Leighton Fisher
  • 5,609
  • 2
  • 18
  • 29

4 Answers4

16

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.

Community
  • 1
  • 1
ColdFusion
  • 2,381
  • 13
  • 14
  • 1
    Thanks! Yah know, this (i.e. my) confusion could have been avoided by a tiny bit more documentation on the W3C folks part. At least now we have your clear (and correct) answer to my question. – Mark Leighton Fisher Jun 14 '13 at 18:26
  • 1
    Just for the record, can you suggest the form that the documentation should or could have taken, in order to avoid your confusion? The responsible W3C WG did put a document at the URI http://www.w3.org/2001/XMLSchema-instance, and [sec. 3.2.7 of the XSD 1.0 Structures spec](http://www.w3.org/TR/xmlschema-1/#d0e3067) does have an explicit description of the schema components involved. Neither of these helped, I gather; did you look at them and find them incomprehensible, or did you look elsewhere? Where did you look? – C. M. Sperberg-McQueen Jun 20 '13 at 21:54
  • That is not correct any more. Instead of XSD following text is displayed at that URL now: $Date: 2001/03/16 20:25:57 $ $Id: XMLSchema-instance.xsd,v 1.4 2001/03/16 20:25:57 ht Exp $ – mentallurg Mar 14 '18 at 18:40
  • 1
    @mentallurg it would be surprising to me if this was true. that text you quote *is* part of the documentation for the XSD. You can look at view-source:https://www.w3.org/2001/XMLSchema-instance to confirm that this is in fact a valid XSD – nightpool Oct 16 '19 at 20:30
3

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.

Mark Leighton Fisher
  • 5,609
  • 2
  • 18
  • 29
  • So is for that reason that we find xml documents where there ins't xml-schema xsd declaration at all? For example like this: – Giorgio Aug 27 '15 at 08:34
3

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">
C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65
Giorgio
  • 1,073
  • 3
  • 15
  • 33
  • 1
    No, we find those because there are silly people who think "Hey, XML is cool! Let's use it!" without bothering to make the effort to not write indeterminate trash that requires special parsing beyond XML, so can't possibly be validated by an XSD. – Gordon Aug 14 '17 at 15:57
3

Here is some updated information on this topic.

XSD 1.1 part 1 §2.6 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.

informatik01
  • 16,038
  • 10
  • 74
  • 104
Michael Kay
  • 156,231
  • 11
  • 92
  • 164