我对这段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 Schema是用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 Schema来验证以前的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架构有问题吗? 非常感谢你
答案 0 :(得分:1)
它正在寻找具有空命名空间的predizione
,但它只能在默认命名空间predizione
中找到http://www.oracolo.it/i-ching
,因为您没有设置elementFormDefault="qualified"
xsd:schema
元素。 You can read more about this attribute and why it's needed here
基本上最简单的解决方法是使用以下内容:
<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"
>