XML验证:“此时没有儿童元素”

我正在尝试根据给定的 XML文件开发XSD语法.给定的 XML文件itemList.xml如下所示.
<?xml version="1.0" encoding = "utf-8"?>
<itemList 
    xmlns="http://www.w3schools.com" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://www.w3schools.com  itemList.xsd" >
     <item>spoon</item>  
     <item>knife</item>
     <item>fork</item>  
     <item>cup</item>
</itemList>

我开发的itemList.xsd文件如下所示.

<schema 
    xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:co="http://www.w3schools.com"
    targetNamespace="http://www.w3schools.com" 
    elementFormDefault="qualified">
<simpleType name="itemType">
    <restriction base="string"/>
</simpleType>
<complexType name="itemListType">
    <sequence>
        <element name="item" type="co:itemType"/>
    </sequence>
</complexType>
<element name="itemList" type="co:itemListType"/>
</schema>

当我使用this XML validator对XSD验证XML时,我得到错误

Cvc-complex-type.2.4.d: Invalid Content Was Found Starting With Element 'item'. No Child Element Is Expected At This Point.. Line '6',Column '12'.

看来我应该在itemList.xsd中重写我的complexType,但是我不知道该怎么做.非常感谢谁能帮助.

您的itemList目前仅由一个项目组成;这是因为默认的粒子基数为1(minOccurs = maxOccurs = 1).

如果您希望多于一个,则需要添加适当数字的maxOccurs属性;为无限制,使用maxOccurs =“无界”…如此:

<element name="item" type="co:itemType" maxOccurs="unbounded"/>

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念