Grendizer
Grendizer

Reputation: 2213

XSD validation error with XML child node

I getting a validation error when trying to validate an XML file against an external XSD file.
I'm getting the following error: cvc-complex-type.2.4.a: Invalid content was found starting with element 'namn'. One of '{name}' is expected.
I guess it has to do with contactperson have nested children...

Here's the XML code

<?xml version="1.0" encoding="ISO-8859-1" ?>

<startfalt>
    <person startnummer="14">
        <namn>
            <fornamn>Charlotte</fornamn>
            <efternamn>Kalla</efternamn>
        </namn>
        <fodelsesiffror>790204-1712</fodelsesiffror>
        <land>Sverige</land>
        <klubb>IK SKidan</klubb>
        <sponsor>Audi</sponsor>
        <traningstimmar>1200</traningstimmar>
        <prispengar valuta="kr">2300000</prispengar>
        <kontaktperson>
            <namn>
                <fornamn>Sven</fornamn>
                <efternamn>Svensson</efternamn>
            </namn>
        </kontaktperson>
    </person>
</startfalt>

Here's my Schema

<?xml version="1.0" encoding="UTF-8" ?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="qualified">

    <xsd:annotation>
        <xsd:documentation>Skidlandslaget</xsd:documentation>
    </xsd:annotation>

    <xsd:element name="startfalt">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="person" type="personType" minOccurs="1" maxOccurs="30" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

    <xsd:complexType name="personType">
        <xsd:sequence>
            <xsd:element name="namn" type="nameType" />
            <xsd:element name="fodelsesiffror" type="xsd:string" />
            <xsd:element name="land" type="xsd:string" />
            <xsd:element name="klubb" type="xsd:string" />
            <xsd:element name="sponsor" type="xsd:string" />
            <xsd:element name="traningstimmar" type="xsd:integer" />
            <xsd:element name="prispengar" type="priceType" />
            <xsd:element name="kontaktperson" type="contactType" />
        </xsd:sequence>

        <!--attribut for person-->
        <xsd:attribute name="startnummer" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:positiveInteger">
                    <xsd:pattern value="\d{2}"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
    </xsd:complexType>

    <xsd:complexType name="nameType">
        <xsd:sequence>
            <xsd:element name="fornamn" type="xsd:string" />
            <xsd:element name="efternamn" type="xsd:string" />
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="priceType" mixed="true">
        <xsd:attribute name="valuta" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:enumeration value="sek" />
                    <xsd:enumeration value="kr" />
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
    </xsd:complexType>

    <xsd:complexType name="contactType">
        <xsd:sequence>
            <xsd:element name="name" type="contactNameType" />
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>

Upvotes: 0

Views: 82

Answers (1)

gmiley
gmiley

Reputation: 6604

You are correct, there is a fairly simple fix for that. Change your contactType to:

<xsd:complexType name="contactType">
    <xsd:sequence>
        <xsd:element name="namn" type="nameType" />
    </xsd:sequence>
</xsd:complexType>

Upvotes: 1

Related Questions