views:

515

answers:

2

When we use a namespace, we should also indicate where its associated XSD is located at, as can be seen in the following example:

<?xml version="1.0"?>
<Artist BirthYear="1958" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://www.webucator.com/Artist"
 xsi:schemaLocation="http://www.webucator.com/Artist Artist.xsd">
 <Name>
  <Title>Mr.</Title>
  <FirstName>Michael</FirstName>
  <LastName>Jackson</LastName>
 </Name>
</Artist>

Here, we have indicated that Artist.xsd should be used for validating the http://www.webucator.com/Artist namespace. However, we are also using the http://www.w3.org/2001/XMLSchema-instance namespace, but we have not specified where its XSD is located at. How do XML parsers know how to handle this namespace?

Update (in response to the first commenter)

So, can we instead of using:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
            http://www.springmodules.org/schema/ehcache
            http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd"&gt;
...
</beans>

use

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:ehcache="http://www.springmodules.org/schema/ehcache"&gt;
...
</beans>

?

Thanks in advance.

A: 

There's no requirement to say where the schema is located. You can do it if you want, but you don't have to.

In this example, all platforms are likely to understand where the schemas for xsi, xml, xsd and soap are all located.


EDIT: Like I said, all platforms are likely to know where the schemas are for these well-known namespaces. Quite likely, they all have copies of the schemas. I use Visual Studio, and it keeps copies of these schemas online, and refers to them as necessary.

John Saunders
Please have a look at the updated post.
Bytecode Ninja
A: 

There are four built in declarations for Xml schemata; type, nil, schemaLocation and noNamespaceSchemaLocation as are "present in every schema by definition." You can read about them in the Xml Schema recommendation.

dkackman
Your link is broken.
John Saunders
oops, copy paste error - fixed
dkackman
Where is the XSD file for the http://www.w3.org/2001/XMLSchema-instance namespace located? How do XML parsers know where is it located? Where is it specified that XML parsers have to know this location by default?
Bytecode Ninja
I don't know where it is located. As far as how various parsers resolve schemas for schema I would be very surprised if they resolve those at runtime by looking for an XSD on the internet the way I think you are envisioning.
dkackman
I know that parsers do not locate it from the internet. However, I want to know about an official and formal statement regarding why in an XML document it is OK to omit the URL for the XMLSchema-instance namespace and probably an implementation advice that parsers can or should use a cached local version of its XSD for validating XML docs.
Bytecode Ninja