Re: FW: User issues with Namespaces in Schema -- {form} qualified vs. unqualified, was [RE: Getting acquainted with schema]

Hi David,

>> To understand why this works, please examine the following instance
>> document, which also validates against the altered schema:
>> 
>> test
>> ====
>> <?xml version="1.0"?>
>> <test:Product xmlns:test="http://lnk.com/test" 
>>               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
>>               xsi:noNamespaceSchemaLocation="/SapphireVM1/xml/test/t1.xsd">
>>       <test:Msg Type="SitRep"/>
>> </test:Product>

It only validates because if you don't supply a schema for an instance
document, then the schema validator uses lax validation and just says
that everything's OK :)

The schema validator uses lax validation against this document because
you've used xsi:noNamespaceSchemaLocation to indicate the location of
the schema for elements in no namespace, but the document element is
test:Product - an element in the http://lnk.com/test namespace, for
which there's been no schema provided.

You need:

<?xml version="1.0"?>
<test:Product xmlns:test="http://lnk.com/test"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://lnk.com/test
                                  /SapphireVM1/xml/test/t1.xsd">
  <test:Msg Type="SitRep"/>
</test:Product>

or, if you don't like using prefixes:

<?xml version="1.0"?>
<Product xmlns="http://lnk.com/test"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://lnk.com/test
                             /SapphireVM1/xml/test/t1.xsd">
  <Msg Type="SitRep"/>
</Product>

>> With those changes, elements defined in the "http://lnk.com/test"
>> namespace are clearly identified in the instance. Also, elements
>> which are locally defined are clearly identified (they don't have a
>> prefix). I added an element (GlobMsg) to demonstrate the
>> difference. And you don't have the disturbing ambiguity evident in
>> your original example.

I'd personally argue that it makes creating the document (whether by
hand or by code) harder, because you have to check the schema to work
out whether you have to put an element in a namespace or not in a
namespace. At least if all local elements are qualified you know that
if an element is from the http://lnk.com/test markup language, it will
be in that namespace.

Plus, I think that:

<?xml version="1.0"?>
<Product xmlns="http://lnk.com/test"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://lnk.com/test
                             /SapphireVM1/xml/test/t1.xsd">
  <Msg Type="SitRep"/>
</Product>

looks cleaner than:

<?xml version="1.0"?>
<test:Product xmlns:test="http://lnk.com/test"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://lnk.com/test
                                  /SapphireVM1/xml/test/t1.xsd">
  <Msg Type="SitRep"/>
</test:Product>

or the equivalent:

<?xml version="1.0"?>
<Product xmlns="http://lnk.com/test"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://lnk.com/test
                             /SapphireVM1/xml/test/t1.xsd">
  <Msg xmlns="" Type="SitRep"/>
</Product>

But this is just a new topic for holy wars - people have strong
feelings either way depending on their backgrounds and experiences
with XML. Horses for courses is what I say :)

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Saturday, 12 January 2002 14:24:15 UTC