Skip to content

How to retrieve min/max occurence ? - wrong value reported by min_occurs/max_occurs #449

@Thomasb81

Description

@Thomasb81

Hello

Using following schema :

IPXACT/1685-2022/index.xsd or in a zip file ipxact_schema_files_20250213.zip

I would like yo retrieve cardinality of every element that can occurred in xml respecting the provided schema.

The execution of following script

import xmlschema

print(xmlschema.__version__)

schema = xmlschema.XMLSchema('../schema/2022/index.xsd')

addressBlock = schema.find("/ipxact:component/ipxact:memoryMaps/ipxact:memoryMap/ipxact:addressBlock")
print('min:',addressBlock.min_occurs)
print('max:',addressBlock.max_occurs)

result = schema.is_valid('test_xmlschema.xml')
print(result)

produces:

4.0.1
min: 1
max: 1
True

While I expect the print of addressBlock.min_occurs to produce 0 and addressBlock.max_occurs to produce None in order to represent the correct cardinality as described in the xs:group of upper level memoryMapGroup

memoryMap.xsd line 408:

	<xs:group name="memoryMap">
		<xs:annotation>
			<xs:documentation>A group elements for a memoryMap</xs:documentation>
		</xs:annotation>
		<xs:choice>
			<xs:element ref="ipxact:addressBlock"/>
			<xs:element ref="ipxact:bank"/>
			<xs:element ref="ipxact:subspaceMap"/>
		</xs:choice>
	</xs:group

memoryMap.xsd line 456:

        <xs:group name="memoryMapGroup">
		<xs:sequence>
			<xs:group ref="ipxact:memoryMap" minOccurs="0" maxOccurs="unbounded"/>
			<xs:element ref="ipxact:memoryRemap" minOccurs="0" maxOccurs="unbounded"/>
			<xs:element ref="ipxact:addressUnitBits" minOccurs="0"/>
			<xs:element name="shared" type="ipxact:sharedType" minOccurs="0">
				<xs:annotation>
					<xs:documentation>When the value is 'yes', the contents of the memoryMap are shared by all the references to this memoryMap, when the value is 'no' the contents of the memoryMap is not shared and when the value is 'undefined' (default) the sharing of the memoryMap is undefined.</xs:documentation>
				</xs:annotation>
			</xs:element>
		</xs:sequence>
	</xs:group>

The validation seems to not take into account the wrong value since the xmlschema is able to validate the attached document.

test_xmlschema.xml.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions