Re: Schemas, namespaces, local, global, in no namespace

> <SNIP>>
> > 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?
>
> [MJG]
>
> My guess is this is just the way XSV reports stuff. Having already reported
> an error with 'item' it doesn't report errors with the content of item
> beause that content is implicitly in error. Or put another way; there is no
> way for XSV to validate the content of 'item' because 'item' itself is
> unexpected.
>
> So yes, there is a problem with 'name' and 'town' but XSV can't tell you
> anything about them because it didn't know what to do with 'item'

OK, that does help. I guess what I don't get is if name and town (and bar and item) are all not associated
with the 'something' namespace that I'm using to schema validate my xml docs, how does XSV (or any
validator) know how to validate them?

Imagine that I dutifly qualify the something namespace in the xml document with "red" and I add a new
element (zip) of type integer (and deliberately give it bad content.
http://www.cookwood.com/xmltests/martin3.xml:

<?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

F:\schemas\martin2.xsd">
 <bar>this is a string</bar>
 <item>
  <name>pen knife</name>
  <town>nyc</town>
  <zip>not a number!</zip>
 </item>
</red:baz>

I add a definition for the zip element in the new schema (http://www.cookwood.com/xmltests/martin3.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"/>
    <element name="zip" type="integer"/>
   </complexType>
  </element>
 </complexType>
 <element name="baz" type="tns:foo"/>
</schema>

XSV properly tells me that the zip element has bad content. But how does it know that if zip isn't in the
target namespace that is defined with the schema?

Thanks for your patience and help!

Liz

Received on Monday, 14 August 2000 09:22:00 UTC