Schemas, namespaces, local, global, in no namespace

Well, I've got most of it, but there's still something that's not quite
clear.

In fact, what I don't understand now is why I'm not getting _enough_
errors:

I recreated Martin's example of the very simple schema creating a very
simple namespace:

<schema xmlns='http://www.w3.org/1999/XMLSchema'
        xmlns:tns='http://example.org/something'
        targetNamespace='http://example.org/something' >

<complexType name='foo'>
    <element name='bar' type='string' />
  </complexType>

  <element name='baz' type='tns:foo' />

</schema>

And I create a little instance:

<?xml version="1.0" encoding="UTF-8"?>
<baz xmlns="http://www.example.org/something"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/something
http://www.cookwood.com/xmltests/martin.xsd">
 <bar>this is a string</bar>
</baz>

(which XML Spy loves and thinks is completely valid). But XSV thinks
it's terrible--'bar' is not allowed here in the 'baz' element, 'baz'
can't end yet, 'bar' is not declared.

But then rereading Martin's post, I say, OK. In the schema, 'foo' and
'baz' are part of the target namespace but 'bar' is a local element in
no namespace, so in the instance, I should declare the 'something'
namespace with a prefix, and use that prefix with the baz element (which
belongs to the something namespace) but I won't use it for 'bar' since
bar is not in the something namespace. And that kind of makes sense. And
XSV likes it:

<?xml version="1.0" encoding="UTF-8"?>
<red:baz xmlns:red="http://www.example.org/something"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/something
http://www.cookwood.com/xmltests/martin.xsd">
 <bar>this is a string</bar>
</red:baz>

(This time XML Spy complains bitterly that "This file is not valid:
Mandatory element 'red:bar' expected in place of 'bar'.)

But I'm guessing that XSV knows better.

Now, I add a bunch of stuff to the schema
(http://www.cookwood.com/xmltests/martin2.xsd):

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/1999/XMLSchema"
 xmlns:tns="http://www.example.org/something"
 targetNamespace="http://www.example.org/something">

 <complexType name="foo">
  <element name="bar" type="string"/>
  <element name="item" >
   <complexType>
    <element name="name" type="string"/>
    <element name="town" type="string"/>
   </complexType>
  </element>
  </complexType>

  <element name="baz" type="tns:foo"/>
  </schema>

because I'm curious what happens to elements inside of elements inside
of elements ('name' and 'town' here). And as long as I use <red:baz
xmlns:red="http://www.example.org/something"...> and don't qualify
anything else, everything is wonderful and XSV is happy (though again
XML Spy thinks I'm an idiot).
(http://www.cookwood.com/xmltests/martingood2.xml)

But just out of curiosity, I leave off the 'red' and try this instance
(http://www.cookwood.com/xmltests/martin2.xml):

<?xml version="1.0" encoding="UTF-8"?>
<baz xmlns="http://www.example.org/something" >
 <bar>this is a string</bar>
 <item><name>pen knife</name>
 <town>nyc</town>
 </item>
</baz>

As expected, XSV gives me errors (and XML Spy doesn't), but curiously,
XSV only complains about bar and item, but not about name and town. Why
isn't there a problem with all of them? If bar and item aren't part of
the 'something' namespace because they are local elements in the schema,
then name and town shouldn't be in any namespace either...and thus there
should be a problem when I declare 'something' as the default namespace
for the whole document (which is what happens when I get rid of the
'red' qualifier).

Why isn't there a problem with name and town?

I'm still missing something, right?

Thanks,
Liz

Liz Castro
Cookwood Press
http:/www.cookwood.com

Received on Friday, 11 August 2000 17:41:00 UTC