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

前端之家收集整理的这篇文章主要介绍了xml – XSD错误:不允许使用字符内容,因为内容类型为空前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我从以下XSD收到验证错误
  1. <?xml version="1.0" ?>
  2. <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  3. <xsd:element name="People">
  4. <xsd:complexType>
  5. <xsd:sequence>
  6. <xsd:element name="Person" maxOccurs="unbounded">
  7. <xsd:complexType>
  8. <xsd:attribute name="name" type="xsd:string" use="required" />
  9. </xsd:complexType>
  10. </xsd:element>
  11. </xsd:sequence>
  12. </xsd:complexType>
  13. </xsd:element>
  14. </xsd:schema>

使用以下XML进行验证时:

  1. <?xml version="1.0" ?>
  2. <People>
  3. <Person name='john'>
  4. a nice person
  5. </Person>
  6. <Person name='sarah'>
  7. a very nice person
  8. </Person>
  9. <Person name='chris'>
  10. the nicest person in the world
  11. </Person>
  12. </People>

返回以下错误

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

我错过了什么?

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

尝试使用xsd进行验证:

  1. <?xml version="1.0" ?>
  2. <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  3. <xsd:element name="People">
  4. <xsd:complexType>
  5. <xsd:sequence>
  6. <xsd:element name="Person" type="Person" maxOccurs="unbounded"/>
  7. </xsd:sequence>
  8. </xsd:complexType>
  9. </xsd:element>
  10.  
  11. <xsd:complexType name="Person">
  12. <xsd:simpleContent>
  13. <xsd:extension base="xsd:string">
  14. <xsd:attribute name="name" type="xsd:string" use="required" />
  15. </xsd:extension>
  16. </xsd:simpleContent>
  17. </xsd:complexType>
  18. </xsd:schema>

猜你在找的XML相关文章