Reputation: 169
I have an XSD with two defined types and a simple XML to validate against. The error message is
src-resolve: Cannot resolve the name 'colorType' to a(n) 'type definition' component
and there are several questions with that error message, but the circumstances seem to be others. Also the example documents are usually big and I have problems seeing the relevant parts. So here is a simple one.
XSD (named svg_export_test.xsd
):
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="test"
attributeFormDefault="unqualified"
elementFormDefault="qualified">
<xs:element name="colorType">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="#[0-9A-Fa-f]{8}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="clothingType">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="color" type="colorType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML (named svg_export_test.xml
in the same folder):
<?xml version="1.0"?>
<t:clothingType xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="svg_export_test.xsd"
xmlns:t="test"
>
<t:name>Shirt</t:name>
<t:color>#00000000</t:color>
</t:clothingType>
Upvotes: 0
Views: 41
Reputation: 163675
Firstly, you've said type="colorType"
, but colorType
isn't a type, it's an element declaration. You need an <xs:simpleType name="colorType">
at the top level of your schema for this to work.
Secondly, if you add this, the type colorType
will be in namespace test
, so to refer to it, you need to use type="t:colorType"
, where the namespace prefix t
is bound to the namespace test
(add xmlns:t="test"
to your xs:schema
element)
The corrected XSD would then be
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="test" xmlns:t="test"
attributeFormDefault="unqualified"
elementFormDefault="qualified">
<xs:simpleType name="colorType">
<xs:restriction base="xs:string">
<xs:pattern value="#[0-9A-Fa-f]{8}"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="clothingType">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="color" type="t:colorType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Upvotes: 1