我一直收到此错误:
“序列”的内容必须与注释匹配?,(元素|组|选择|序列|任何)*)。发现一个问题,起始于:simpleType。 xsd必须包含一个名为simpleType的自定义示例。
我试图包含该示例,但无法弄清楚我在做什么错。
这是我的XML:
<?xml version="1.0" encoding="UTF-8"?>
<famous_landmarks>
<landmark>
<name language="English">St Basil's Cathedral</name>
<name language="Russian">собо́р Васи́лия Блаже́нного</name>
<location>Moscow, Russia</location>
<height unit="feet">156</height>
<year_built>1561</year_built>
</landmark>
<landmark>
<name language="English">St Peter's Cathedral</name>
<name language="Latin">Basilica Sancti Petri</name>
<location>Vatican City</location>
<!-- It is an independent city-state enclaved within Rome, Italy -->
<height unit="feet">448</height>
<year_built>1626</year_built>
</landmark>
<landmark>
<name language="English">Christ the Redeemer</name>
<name language="Portuguese">Cristo Redentor</name>
<location>Rio de Janeiro, Brazil</location>
<height unit="feet">125</height>
<year_built>1931</year_built>
</landmark>
<landmark>
<name language="English">Hagia Sophia</name>
<name language="Greek">Αγία Σοφία</name>
<!-- Originally a cathedral, it was converted into a mosque and then a museum -->
<location>Istanbul, Turkey</location>
<height unit="feet">180</height>
<year_built>537</year_built>
<image file="hagiasophia.png"/>
</landmark>
<landmark>
<name language="English">Brandenburg Gate</name>
<name language="German">Brandenburger Tor</name>
<location>Berlin, Germany</location>
<height unit="feet">85</height>
<year_built>1791</year_built>
</landmark>
<landmark>
<name language="English">Neuschwanstein Castle</name>
<name language="German">Schloss Neuschwanstein</name>
<location>Hohenschwangau, Germany</location>
<height unit="feet">213</height>
<year_built>1886</year_built>
</landmark>
<landmark>
<name language="English">Dome of the Rock</name>
<name language="Arabic">Qubbat al-Sakhrahة</name>
<location>Jerusalem, Israel</location>
<height unit="feet">115</height>
<year_built>692</year_built>
</landmark>
<landmark>
<name language="English">Statue of Liberty</name>
<location>New York City, United States</location>
<height unit="feet">305</height>
<year_built>1886</year_built>
</landmark>
<landmark>
<name language="English">Big Ben</name>
<location>London, England</location>
<height unit="feet">315</height>
<year_built>1859</year_built>
</landmark>
<landmark>
<name language="English"> Angel of Independence</name>
<name language="Spanish">Monumento a la Independencia</name>
<location>Mexico City, Mexico</location>
<height unit="feet">148</height>
<year_built>1910</year_built>
</landmark>
</famous_landmarks>
这是我的xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="www.famouslandmarks.com" targetNamespace="www.famouslandmarks.com">
<xs:element name="famous_landmarks">
<!--feature 2: complex type element containing child elements-->
<xs:complexType>
<xs:sequence>
<xs:element name="name">
<xs:complexType>
<!--feature 6: required attribute-->
<xs:attribute name="language" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<!--feature 8: specification of a set of acceptable values-->
<xs:enumeration value="English" />
<xs:enumeration value="Arabic" />
<xs:enumeration value="German" />
<xs:enumeration value="Greek" />
<xs:enumeration value="Latin" />
<xs:enumeration value="Portuguese" />
<xs:enumeration value="Russian" />
<xs:enumeration value="Spanish" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<!--feature 3: named custom simple type-->
<xs:simpleType name="location_type">
<xs:restriction base="xs:string" />
</xs:simpleType>
<xs:element name="location" type="location_type" />
<!--feature 9: specification of minimum and maximum number of occurrences-->
<xs:element name="height" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<!--feature 4: non-string data type-->
<xs:restriction base="xs:integer">
<!--feature 7: range of acceptable values-->
<xs:minInclusive value="0" />
<xs:maxInclusive value="448" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<!--feature 1: simple type element -->
<xs:element name="year_built" type="xs:gYear" />
<!--feature 5: "fixed" attribute-->
<xs:element name="era" type="xs:string" fixed="AD" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我竭尽全力,不胜感激。
错误消息实际上非常清楚地指出了问题...但是仅当您知道如何读取XML Schema错误消息时。
错误消息是在一个序列中,仅允许某些类型的子对象。它们是:元素,组引用,选择组,序列组或xs:any。每个选项都可以有一个模式注释。
有了这些信息,现在问题出在哪里就很明显了。您的xs:sequence包含一个简单的类型声明,这是不允许的。
有两种方法可以解决此问题
将xs:simpleType移动到架构的顶层(以便它是元素声明“著名地标”的同级)。如果location_type被多个元素使用,请执行此操作。
从xs:simpleType声明中删除'name'属性,并使它成为元素声明'location'的child。您还应该从“位置”中删除“类型”属性,因为不会有名称为“ location_type”的全局简单类型。如果location_type仅用于此元素声明,请执行此操作。