tags:

views:

18

answers:

1

Hello! I have a problem with the validation of this piece of XML:

<?xml version="1.0" encoding="UTF-8"?>
<i-ching xmlns="http://www.oracolo.it/i-ching"&gt;
    <predizione>
        <esagramma nome="Pace">
            <trigramma>
                <yang/><yang/><yang/>
            </trigramma>
            <trigramma>
                <yin/><yin/><yin/>
            </trigramma>
        </esagramma>
        <significato>Questa combinazione preannuncia
            <enfasi>boh</enfasi>, e forse anche <enfasi>mah,
                chissa</enfasi>.</significato>
    </predizione>
    <predizione>
        <esagramma nome="Ritorno">
            <trigramma>
                <yang/><yin/> <yin/>
            </trigramma>
            <trigramma>
                <yin/><yin/><yin/>
            </trigramma>
        </esagramma>
        <significato>Si prevede con certezza <enfasi>qualcosa</enfasi>,
            <enfasi>ma anche <enfasi>no</enfasi></enfasi>.</significato>
    </predizione>
</i-ching>

This XML Schema was developed with Russian Dolls technique:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.oracolo.it/i-ching"
    targetNamespace="http://www.oracolo.it/i-ching"
    > 

<xsd:element name="i-ching">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="predizione" minOccurs="0" maxOccurs="64">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="esagramma">
                            <xsd:complexType>
                                <!-- vi sono 2 trigrammi -->
                                <xsd:sequence>
                                    <xsd:element name="trigramma" minOccurs="2" maxOccurs="2">
                                        <xsd:complexType>
                                            <xsd:sequence minOccurs="3" maxOccurs="3">
                                                <xsd:choice>
                                                    <xsd:element name="yang"/>
                                                    <xsd:element name="yin"/>
                                                </xsd:choice>
                                            </xsd:sequence>
                                        </xsd:complexType>
                                    </xsd:element>
                                </xsd:sequence>
                                <xsd:attribute name="nome" type="xsd:string"/>
                            </xsd:complexType>
                        </xsd:element>
                        <!-- significato: context model misto -->
                        <xsd:element name="significato">
                            <xsd:complexType mixed="true">
                                <xsd:sequence>
                                    <xsd:element name="enfasi" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
                                </xsd:sequence>
                            </xsd:complexType>
                        </xsd:element>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

</xsd:schema>

For exercise I have to develop an XML Schema to validate the previous XML. The problem is that oxygen says me this:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'predizione'. One of '{predizione}' is expected. Start location: 3:6 End location: 3:16 URL: http://www.w3.org/TR/xmlschema-1/#cvc-complex-type

why? is it something wrong with my xml schema? thank you very much

+1  A: 

It's looking for predizione with an empty namespace but it can only find predizione in the default namespace http://www.oracolo.it/i-ching, because you don't have elementFormDefault="qualified" set up in the xsd:schema element. You can read more about this attribute and why it's needed here.

Basically the simplest fix for you is to use the following:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.oracolo.it/i-ching"
    targetNamespace="http://www.oracolo.it/i-ching"
    elementFormDefault="qualified"
    >
Welbog
Thank you very much! I misunderstood this argument while i was studying: now it's clear and i correct my schema. Thank you again
farhad