W3C home > Mailing lists > Public > xmlschema-dev@w3.org > March 2008

RE: Composition by extension in namespaced schema

From: Gavin Kistner <phrogz@mac.com>
Date: Fri, 14 Mar 2008 13:34:50 -0700
To: Michael Kay <mike@saxonica.com>
Cc: xmlschema-dev@w3.org
Message-ID: <94D1E3AE-0118-1000-8134-52207B17610B-Webmail-10021@mac.com>

On Friday, March 14, 2008, at 12:24PM, "Michael Kay" <mike@saxonica.com> wrote:
>> I need to use a targetNamespace (or is it an xmlns?) in my 
>> schema so that I can validate other files without having to 
>> add noNamespaceSchemaLocation to those files. Can someone 
>> help me understand the core issue here, and (especially) how 
>> to modify the file to accomplish the goal?

>The type is in a namespace, so the reference to it needs to be prefixed:
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
>> targetNamespace="http://www.foo.com/"
>  xmlns:tgt="http://www.foo.com/">
>>   <xs:complexType name="mammal" />
>>   <xs:element name="dog">
>>     <xs:complexType><xs:complexContent>
>>     	<xs:extension base="tgt:mammal" />
>>     </xs:complexContent></xs:complexType>
>>   </xs:element>
>> </xs:schema>

Thank you again; that (oh so simple, and now understandable, change) fixed the validation of the XSD itself. However, when I try to validate an XML document against this schema, I get a new (confusingly-reported) error:

<!-- foo.xsd -->
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.foo.com" xmlns:foo="http://www.foo.com">
  <xs:element name="root">
        <xs:element ref="foo:native"/>
        <xs:element name="bjork"><xs:simpleType><xs:restriction base="xs:string" /></xs:simpleType></xs:element>
  <xs:element name="native"/>  

<!-- test.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.foo.com foo.xsd" xmlns="http://www.foo.com">
  <native />
  <bjork>Hello There</bjork>

  SystemID: E:\test.xml
  Location: 6:4
  Description: cvc-complex-type.2.4.a: Invalid content was found starting with element 'bjork'. One of '{bjork}' is expected.
  URL: http://www.w3.org/TR/xmlschema-1/#cvc-complex-type

As shown above, the 'native' element in the sequence works with the namespace, but the inline element does not. Is this a true validation error, or is this a bug in the validator that I need to work around by just moving all elements to be defined at the top level?
Received on Friday, 14 March 2008 20:35:29 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:56:14 UTC