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

xml – XSD错误:不允许使用字符内容,因为内容类型为空

发布时间:2020-12-16 07:50:40 所属栏目:百科 来源:网络整理
导读:我从以下XSD收到验证错误: ?xml version="1.0" ?xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsd:element name="People" xsd:complexType xsd:sequence xsd:element name="Person" maxOccurs="unbounded" xsd:complexType xsd:attribute name
我从以下XSD收到验证错误:
<?xml version="1.0" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <xsd:element name="People">
      <xsd:complexType>
         <xsd:sequence>
            <xsd:element name="Person" maxOccurs="unbounded">
                 <xsd:complexType>
                    <xsd:attribute name="name" type="xsd:string" use="required" />
                 </xsd:complexType>
             </xsd:element>
         </xsd:sequence>
      </xsd:complexType>
   </xsd:element>
</xsd:schema>

使用以下XML进行验证时:

<?xml version="1.0" ?>
<People>
    <Person name='john'>
        a nice person
    </Person>
    <Person name='sarah'>
        a very nice person
    </Person>
    <Person name='chris'>
        the nicest person in the world
   </Person>
</People>

返回以下错误:

lxml.etree.XMLSyntaxError: Element 'Person': Character content is not allowed,because the content type is empty.

我错过了什么?

它说“人”不能包含字符串.要使用xsd验证xml,请使用以下命令:
<?xml version="1.0" ?>
<People>
    <Person name='john'>
    </Person>
    <Person name='sarah'>
    </Person>
    <Person name='chris'>
   </Person>
</People>

尝试使用xsd进行验证:

<?xml version="1.0" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <xsd:element name="People">
      <xsd:complexType>
         <xsd:sequence>
         <xsd:element name="Person" type="Person" maxOccurs="unbounded"/>
         </xsd:sequence>
      </xsd:complexType>
   </xsd:element>

   <xsd:complexType name="Person">
     <xsd:simpleContent>
        <xsd:extension base="xsd:string">
           <xsd:attribute name="name" type="xsd:string" use="required" />
        </xsd:extension>
    </xsd:simpleContent>
   </xsd:complexType>
</xsd:schema>

(编辑:李大同)

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

    推荐文章
      热点阅读