Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 755
holic87 Avatar asked Dec 17 '25 10:12

holic87


1 Answers

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).

like image 138
sho222 Avatar answered Dec 21 '25 04:12

sho222



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!