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.
Either add the
xmlns="test"attribute to the schema element in order declare that default namespace for this schema is “test” or addxmlns:t="test"to declare thattis the prefix for the “test” namespace and use that prefix liketype=t:testSubTypewhen referencing types that you defined in this namespace (which you’re doing by saying test is your targetNamespace).