The global declaration of the title
attribute puts that attribute in the target namespace urn:test
. That also means that you must qualify the reference to the attribute, both in the schema and in the instance document. By default, unqualified attributes have no namespace.
<xs:schema targetNamespace="urn:test"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
xmlns="urn:test" xmlns:test="urn:test" >
....
<xs:complexType name="ContentType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute ref="test:title" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:attribute name="title" type="xs:string" />
and
<root xmlns="urn:test" xmlns:test="urn:test" >
<content test:title="Title">
Content comes here...
</content>
</root>
This whole thing is quite subtle and when I try to validate the original instance document in ecplise I get two very confusing errors:
- The
title
attribute cannot appear on the content element. This refers to the unqualified use of the attribute, and - The
title
element must appear on the content element. This refers to the missing qualifiedtest:title
attribute.
Granted, the error message could use a bit more context information.