xmlschema icon indicating copy to clipboard operation
xmlschema copied to clipboard

documentation element: character data between child elements not allowed

Open woutdenolf opened this issue 4 months ago • 2 comments

I'm trying to use xmlschema and found a validation error which we don't get with lxml (see https://github.com/nexusformat/definitions/issues/1368)

import xmlschema
xmlschema.XMLSchema("nxdl.xsd")
Traceback (most recent call last):
  File "/home/denolf/virtualenvs/nexus/lib/python3.10/site-packages/xmlschema/validators/schemas.py", line 1197, in _parse_inclusions
    self.include_schema(location, self.base_url)
  File "/home/denolf/virtualenvs/nexus/lib/python3.10/site-packages/xmlschema/validators/schemas.py", line 1264, in include_schema
    schema = type(self)(
  File "/home/denolf/virtualenvs/nexus/lib/python3.10/site-packages/xmlschema/validators/schemas.py", line 482, in __init__
    self.parse_error(e.reason or e, elem=e.elem)
  File "/home/denolf/virtualenvs/nexus/lib/python3.10/site-packages/xmlschema/validators/xsdbase.py", line 196, in parse_error
    raise error
xmlschema.validators.exceptions.XMLSchemaParseError: character data between child elements not allowed:

Schema component:

  <xs:element xmlns:xs="http://www.w3.org/2001/XMLSchema" name="example">m^2</xs:element>

Path: /xs:schema/xs:simpleType[4]/xs:annotation/xs:documentation/xs:element[1]

Schema URL: file:///tmp/nexus_definitions/nxdlTypes.xsd

Origin URL: file:///tmp/nexus_definitions/nxdl.xsd

The issue is this

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
	targetNamespace="http://definition.nexusformat.org/nxdl/3.1"
	xmlns:nxdl="http://definition.nexusformat.org/nxdl/3.1"
	elementFormDefault="qualified">

	<xs:simpleType name="NX_ANGLE">
		<xs:annotation>
			<xs:documentation>
				units of angle
				<xs:element name="example">rad</xs:element>
			</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:string" />
	</xs:simpleType>
	
</xs:schema>

The docs https://www.w3schools.com/xml/el_documentation.asp say that

 <documentation
source=URI reference
xml:lang=language>

Any well-formed XML content

</documentation> 

I'm not sure what Any well-formed XML content means but in xmlschema it means either plain text or children, not both? Can anyone provide additional context? I'm not that familiar with XMLSchema.

woutdenolf avatar Mar 04 '24 05:03 woutdenolf