XSD: Import von komplexen Typen nicht funktioniert

Ich habe ein XML-schema schema.xsd mit benutzerdefinierten Typen in außen-Datei types.xsd. Ich weiß nicht, warum mein Komplex-Typ typeComplex ist nicht korrekt validiert. Einfache Typen wie typeSimple funktioniert ok. Was ist falsch mit, dass ?

Eclipse sagen:

cvc-complex-type.2.4.a: Ungültiger content wurde gefunden, beginnend mit
element 'a'. One of '{"http://www.example.org/types":a}' erwartet wird.

schema.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.org/schema" elementFormDefault="qualified"
    xmlns:t="http://www.example.org/types">

    <xs:import schemaLocation="types.xsd" namespace="http://www.example.org/types" />

    <xs:element name="root">
        <xs:complexType>
            <xs:all>
                <xs:element name="simple" type="t:typeSimple" />
                <xs:element name="complex" type="t:typeComplex" />
            </xs:all>
        </xs:complexType>
    </xs:element>

</xs:schema>

Arten.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.org/types" xmlns="http://www.example.org/types"
    elementFormDefault="qualified">

    <xs:simpleType name="typeSimple">
        <xs:restriction base="xs:string">
            <xs:length value="3" />
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="typeComplex">
        <xs:sequence>
            <xs:element name="a" type="xs:string" />
            <xs:element name="b" type="xs:string" />
        </xs:sequence>
    </xs:complexType>
</xs:schema>

text.xml - nicht gültig mit xsd - Warum ?

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://www.example.org/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.example.org/schema schema.xsd " xmlns:t="http://www.example.org/types">
    <simple>XXX</simple>
    <complex>
        <a></a> <!-- not valid here; Eclipse say: cvc-complex-type.2.4.a: Invalid content was found starting with element 'a'. One of '{"http://www.example.org/types":a}' is expected. -->
        <b></b>
    </complex>
</root>
InformationsquelleAutor marioosh | 2012-04-26
Schreibe einen Kommentar