开发者

XML targetNamespace and unqualified declaration of elements

开发者 https://www.devze.com 2023-04-12 08:45 出处:网络
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:

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">
    <x开发者_运维技巧s: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 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号