Is xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" a special case in XML?

When we use the namespace, we must also indicate where its associated XSD is located, as shown 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 indicated that Artist.xsd should be used to check the http://www.webucator.com/Artist namespace. However, we also use the http://www.w3.org/2001/XMLSchema-instance namespace, but we did not indicate where its XSD is located. How do XML parsers know how to handle this namespace?

Update (in response to the first commenter)

So, can we instead 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" 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"> ... </beans> 

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"> ... </beans> 

?

+7
xml xml-namespaces xsd
source share
4 answers

How do XML parsers know how to handle this namespace?

They do not, except when they do. The basic idea is that the line http://www.w3.org/2001/XMLSchema-instance works like a magic cookie. Either the processing software was programmed to recognize it, and thus act based on what it means or not.

Thus, with the help of a simple fact of recognition, “knowledge” also comes of what it represents: a “namespace” that defines four attributes ('type', 'nil', 'schemaLocation' and 'noNamespaceSchemaLocation') with fixed predefined values.

In other words, if you “know” that the string “ http://www.w3.org/2001/XMLSchema-instance 'means”, then you also automatically know that an attribute named xsi: schemaLocation “means”: indicates schema documents encoded in the W3C XML Schema formalism.

This goes beyond what XML Namespaces Rec actually provides (which is just some routine about "universal names" or something else). It uses the convention that the namespace syntax (using colonized names) was deployed to hard-code the semantic understanding: "where to find the schema in the W3C XML Schemas formalism for this document instance." It all depends on a preliminary understanding of this magic cookie string.

You might get the impression that the namespace should have a schema and a machine being processed on this, and only in the W3C XML Schemas formalism to load. None of them are necessarily true. There are other schema formalities (SGML / XML DTD, Relax-NG, both of which, unlike W3C XML schemas, are international standards ); the definition of the namespace should not be machine readable (it can be prose, because in fact it is for the namespace http://www.w3.org/2001/XMLSchema-instance '!); and the namespace does not have to be formally defined at all, because all lines of the namespace are guaranteed to function as a difference marker.

+9
source

No need to say where the circuit is located. You can do this if you want, but you don't need to.

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


EDIT: As I said, all platforms probably know where the schemas are for these well-known namespaces. It is likely that everyone has copies of the circuits. I use Visual Studio and it stores copies of these diagrams on the Internet and references them as needed.

+2
source

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

+2
source

If you look at the content: http://www.w3.org/2001/XMLSchema-instance , you find that there is text:

 ... <xs:schema targetNamespace="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/1999/xhtml"> <xs:annotation> <xs:documentation> <h1>XML Schema instance namespace</h1> <p>See <a href="http://www.w3.org/TR/xmlschema-1/">the XML Schema Recommendation</a> for an introduction</p> ... 

Because xmlns="http://www.w3.org/1999/xhtml" you see the link above as an HTML document.

According to http://www.w3.org/TR/xmlschema-1/#schema-loc (restriction of representation of a scheme: a strategy for placing a document of a scheme) processors with support for a scheme can implement any combination of the following strategies, in any order:

  • An attempt to resolve the namespace name to look up such a resource.

So http://www.w3.org/2001/XMLSchema-instance points to itself (yes, recursion !!).

See a similar answer: Where is the XSD file for http://www.w3.org/2001/XMLSchema-instance "?

PS . Any specialized XML processor can consider http://www.w3.org/2001/XMLSchema-instance as a known thing, without actually downloading this definition (and most of them do this).

SFC . Semantics http://www.w3.org/2001/XMLSchema-instance defined by the XML Schema http://www.w3.org/TR/xmlschema-1/

0
source

All Articles