XSD error: character content is not allowed because the content type is empty

I get 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> 

It returns the following error:

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

What am I missing?

+6
source share
1 answer

He says that "Face" cannot contain a string. To check the xml with this xsd use this:

 <?xml version="1.0" ?> <People> <Person name='john'> </Person> <Person name='sarah'> </Person> <Person name='chris'> </Person> </People> 

Try this for xsd to check:

 <?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> 
+13
source

Source: https://habr.com/ru/post/899260/


All Articles