holic87
holic87

Reputation: 791

XML targetNamespace and unqualified declaration of elements

I'm somewhat confused as to how the targetNamespace attribute in an XML schema affects the naming of elements. I'm getting an error validating the following:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="test" version="1.0">
    <xs:element name="testType" type="testType"/>
    <xs:complexType name="testType">
        <xs:sequence>
            <xs:element name="testSubtype" type="testSubType" />
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="testSubType">
        <!-- some fields -->
    </xs:complexType>
</xs:schema>

XMLSpy is stating it Cannot resolve the unqualified declaration or definition 'testSubType'. How can I resolve this? I need to keep the targetNamespace attribute in there. I've tried changing testSubType to test:testSubType in various areas but this doesn't seem to work.

Upvotes: 3

Views: 1725

Answers (1)

sho222
sho222

Reputation: 722

Either add the xmlns="test" attribute to the schema element in order declare that default namespace for this schema is "test" or add xmlns:t="test" to declare that t is the prefix for the "test" namespace and use that prefix like type=t:testSubType when referencing types that you defined in this namespace (which you're doing by saying test is your targetNamespace).

Upvotes: 6

Related Questions