- 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
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:complexType> <xs:sequence> <xs:element ref="foo:native"/> <xs:element name="bjork"><xs:simpleType><xs:restriction base="xs:string" /></xs:simpleType></xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="native"/> </xs:schema> <!-- 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> </root> <!-- 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