加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 07:52:58 所属栏目:百科 来源:网络整理
导读:我正在尝试根据给定的 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://ww
我正在尝试根据给定的 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"/>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读