TimWagaman
TimWagaman

Reputation: 1008

XSD: Unable to use type defined in the same XSD

I'm writting the following XSD, however I'm having problems with it. For whatever reason, I'm not being allowed to use my simple types that I define in my XSD. I'm getting this error: Cannot resolve the name 'mySimpleType1' to a(n) 'simpleType definition' component.

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns="http://myNamespace" 
    targetNamespace="http://myDifferentNamespace" 
    elementFormDefault="qualified" 
    attributeFormDefault="unqualified">

    <xsd:simpleType name="mySimpleType1">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="Added"/>
            <xsd:enumeration value="Modified"/>
            <xsd:enumeration value="Deleted"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="mySimpleType2">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="foo"/>
            <xsd:enumeration value="bar"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:attributeGroup name="myAttributeGroup">
        <xsd:attribute name="attribute1" type="mySimpleType1" use="optional"/>
        <xsd:attribute name="attribute2" type="mySimpleType2" use="optional"/>
    </xsd:attributeGroup>
</xsd:schema>

Upvotes: 0

Views: 1251

Answers (2)

Tharok
Tharok

Reputation: 1026

The problem is mySimpleType1 is lookuped from xmlns http://myNamespace (no prefix in type - xmlns without suffix is used), but you have defined it in http://myDifferentNamespace (defined by targetNamespace).

You probably want to use xmlns identical with targetNamespace.

Otherwise you need to define for example xmlns:mydiff="http://myDifferentNamespace" and to refer types as type="mydiff:mySimpleType1".

Check https://stackoverflow.com/a/43336017/1576461 for more info about xmlns.

Upvotes: 0

Steve H.
Steve H.

Reputation: 6947

No namespace prefix is on your target namespace...

I would suggest reading this: http://msdn.microsoft.com/en-us/library/aa258639(v=sql.80).aspx

Here's another good guide to creating schema: http://www.ibm.com/developerworks/library/xml-schema/

Upvotes: 1

Related Questions