基于现有 XML 开发 XML 模式的问题

问题描述 投票:0回答:1

我在验证这段 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>

此 XML 模式是使用 Russian Dolls 技术开发的:

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

为了练习,我必须开发一个 XML 架构来验证以前的 XML。问题是氧气对我说:

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

为什么?我的 xml 架构有问题吗? 非常感谢你

xml xsd
1个回答
1
投票

它正在寻找具有空命名空间的

predizione
,但它只能在默认命名空间
predizione
中找到
http://www.oracolo.it/i-ching
,因为您没有在
elementFormDefault="qualified"
元素中设置
xsd:schema
您可以在此处阅读有关此属性以及为什么需要它的更多信息

基本上,最简单的修复方法是使用以下方法:

<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"
    >
© www.soinside.com 2019 - 2024. All rights reserved.