XSD 错误:不允许字符内容,因为内容类型为空
我从以下 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.
我缺少什么?
I am getting a validation error from the following 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>
when using the following XML to validate:
<?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>
Returns the following error:
lxml.etree.XMLSyntaxError: Element 'Person': Character content is not allowed, because the content type is empty.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它说“Person”不能包含字符串。对于要使用该 xsd 进行验证的 xml,请使用以下命令:
尝试对 xsd 进行验证:
It's saying that the "Person" cannot include a string. For the xml to validate with that xsd use this :
Try this for the xsd for validation :
如果 XML 正确并且您希望 XSD 支持字符串内容(有或没有其他子元素),您可以简单地在复杂类型上添加
mixed=true
属性:混合
属性:If the XML is correct and you want to the XSD to support string content (with or without other child elements), you can simply add the
mixed=true
attribute on the complexType:The
mixed
attribute:对我来说,当我将值元素添加到之前只有属性的复杂类型时,错误就解决了。
For me the error was solved when I added value element to the complex type which before had only attribute.