Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What effect does the attribute noNamespaceSchemaLocation have on XML parsing?

Tags:

xml

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?

like image 287
Jops Avatar asked Mar 24 '13 01:03

Jops


1 Answers

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.

like image 82
Michael Kay Avatar answered Oct 13 '22 01:10

Michael Kay