开发者

Problem with develop of XML Schema based on an existent XML

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">
    <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


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"
    >
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜