12

By definition:

The noNamespaceSchemaLocation attribute references an XML Schema document that does not have a target namespace.

How will this attribute ever alter the result of parsing?

For example, take this XML:

<?xml version="1.0"?>
<name
  xmlns="http://www.example.com/name"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.example.com/name schema/schema.xsd"
  title="Mr.">
   <first>John</first>
   <middle>M</middle>
   <last>Doe</last>
</name>

referring to this schema:

<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:target="http://www.example.com/name"
targetNamespace="http://www.example.com/name" elementFormDefault="qualified">
  <element name="name">
    <complexType>
      <sequence>
        <element name="first" type="string"/>
        <element name="middle" type="string"/>
        <element name="last" type="string"/>
      </sequence>
      <attribute name="title" type="string"/>
    </complexType>
  </element>
</schema>

I removed these namespace declarations from the schema:

xmlns:target="http://www.example.com/name" 
targetNamespace="http://www.example.com/name" 

without even using the noNamespaceSchemaLocation attribute in the referencing XML, no error was thrown. Why do we even need this attribute in the first place?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Jops
  • 22,535
  • 13
  • 46
  • 63

1 Answers1

11

The attribute has no effect on an XML parser. It may affect the behaviour of an XML Schema Processor if appropriate options are set; and it may similarly affect the behaviour of a program that combines the functions of XML parsing and XML schema validation. It tells a schema processor where to look for a schema describing the document.

But even with a schema processor, the noNamespaceSchemaLocation attribute will not affect the validation of a document like yours where the elements are all in a namespace.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Thanks for the response Michael. I suppose my question should have been "What effect does the attribute noNamespaceSchemaLocation have on XML *validation*?". If part of my document doesn't have a namespace, you mean that's the time noNamespaceSchemaLocation's effect would kick in and remedy the overlapping 'no namespaces' of the data and the schema? – Jops Mar 24 '13 at 10:39
  • 4
    The attribute tells the schema processor where to look for a schema that can be used to validate elements that are in no namespace. In your example, there aren't any such elements. – Michael Kay Mar 26 '13 at 18:16
  • Ah, cool. Thanks for the clarification Michael. Fully understood now. – Jops Mar 27 '13 at 00:50