How sissaschool/xmlschema works
Purpose and Entry Points
xmlschema is a Python library implementing XML Schema (XSD) 1.0 and 1.1. Its public API constructs schema objects, validates XML, decodes XML into Python/JSON-compatible data, and encodes data back to XML. Main package exports are rooted at xmlschema/__init__.py; command-line access is provided by xmlschema/cli.py. Packaging/runtime metadata is in pyproject.toml.
Schema Construction and Validation Core
Schema parsing, component registration, and XSD-version-specific schema behavior are centered in xmlschema/validators/schemas.py, with common schema-component contracts and validation entry points in xmlschema/validators/xsdbase.py. The validator subsystem models XSD declarations and constraints: elements/types/groups in xmlschema/validators/elements.py, xmlschema/validators/complex_types.py, and xmlschema/validators/groups.py; runtime validation mechanics are in xmlschema/validators/validation.py. This is the primary control boundary: parsed XSD definitions become an in-memory schema graph, then XML instances are checked against it.
XML Resource Loading and Security Boundary
All schema and instance inputs—filesystem paths, URLs, streams, strings, and XML trees—pass through the resource layer: xmlschema/resources/xml_resource.py, xmlschema/resources/xml_loader.py, and xmlschema/resources/parsers.py. Fetching and location resolution are separated into xmlschema/resources/fetchers.py and xmlschema/locations.py. This layer is architecturally important because it controls remote/local resource access and uses protected XML parsing that forbids entities, limiting XML entity attacks before documents reach validators.
Decode/Encode and Data Binding Flow
A schema can decode validated XML to native Python structures or encode Python/JSON-like input to XML. Converter policy is abstracted by xmlschema/converters/base.py; built-in mapping conventions include xmlschema/converters/parker.py, xmlschema/converters/badgerfish.py, and xmlschema/converters/jsonml.py. xmlschema/dataobjects.py provides DataElement-based bindings. Flow is: XML resource → schema validation/typed traversal → converter or data object output; encoding reverses this path through schema-aware element construction and validation.
Namespaces, XPath, and Schema Navigation
QName and namespace normalization underpin both schema compilation and instance processing through xmlschema/namespaces.py and xmlschema/names.py. Schema-facing XPath support is isolated in xmlschema/xpath/mixin.py, xmlschema/xpath/proxy.py, and specialized parsers such as xmlschema/xpath/assertion_parser.py. The library depends on the external elementpath package for XPath-related capabilities, while Python’s ElementTree supplies the base XML tree runtime.
Built-in Standards and Inter-Schema Dependencies
The package ships standards schemas so schema construction works offline and resolves core XSD definitions predictably: xmlschema/schemas/XSD_1.0/XMLSchema.xsd, xmlschema/schemas/XSD_1.1/XMLSchema.xsd, and xmlschema/schemas/XML/xml.xsd. Additional bundled vocabularies, including WSDL and XML Signature schemas, live under xmlschema/schemas/WSDL/ and xmlschema/schemas/DSIG/. Schema include/import/redefine resolution crosses the resource-loading boundary and feeds back into the schema graph.
Higher-Level Documents and Generation
Document-oriented convenience APIs are in xmlschema/documents.py; schema/resource export and offline materialization are in xmlschema/exports.py. Optional extensions provide static Python binding generation from Jinja templates in xmlschema/extras/codegen.py and xmlschema/extras/templates/python/bindings.py.jinja, plus WSDL support in xmlschema/extras/wsdl.py. These sit above, rather than replace, the validator/resource core.
Runtime and Delivery
This is a Python package, not a service or web application. Material external interfaces are local filesystems, remote URLs for XML/XSD retrieval, Python ElementTree, and elementpath. GitHub Actions validate project metadata and XML Schema test coverage via .github/workflows/publiccode-yml-validation.yml and .github/workflows/test-xmlschema.yml; the extensive fixtures under tests/test_cases/ define compatibility and regression behavior across XSD, XML, namespaces, WSDL, decoding, and serialization.
Main entry points: schemas.py Schema construction · xml_resource.py XML resource · validation.py Instance validation · __init__.py Package API
Components 20
Public interfaces
- Package API
xmlschema/__init__.py - CLI
xmlschema/cli.py
Schema core
- Schema construction · Builds version-specific in-memory schema graphs.
xmlschema/validators/schemas.py - Schema contracts
xmlschema/validators/xsdbase.py - XSD declarations
xmlschema/validators/elements.py - Instance validation
xmlschema/validators/validation.py - Names and namespaces
xmlschema/namespaces.py - Schema XPath
xmlschema/xpath/mixin.py
Resource boundary
Protected parsing and URI access.
- XML resource · Accepts paths, URLs, streams, strings, and trees.
xmlschema/resources/xml_resource.py - Protected XML loader · Forbids XML entities before validation.
xmlschema/resources/xml_loader.py - Fetch and locations
xmlschema/resources/fetchers.py - Bundled standards
xmlschema/schemas/XSD_1.1/XMLSchema.xsd
Data binding
- Converter policy
xmlschema/converters/base.py - DataElement bindings
xmlschema/dataobjects.py
Higher-level features
- Document APIs
xmlschema/documents.py - Schema export
xmlschema/exports.py - Python binding generation
xmlschema/extras/codegen.py
Other components
- elementpath
- ElementTree
- XML and XSD inputs
Connections 20
- Package API → Schema construction: constructs schemas
- CLI → Package API: uses
- XML and XSD inputs → XML resource: opens
- XML resource → Protected XML loader: loads XML
- Protected XML loader → ElementTree: parses with
- XML resource → Fetch and locations: resolves locations
- Fetch and locations → Bundled standards: uses offline standards
- XML resource → Schema construction: supplies schema documents
- Schema construction → Schema contracts: implements contracts
- Schema construction → XSD declarations: registers components
- Schema construction → Names and namespaces: normalizes QNames
- Schema construction → Schema XPath: supports assertions
- Schema XPath → elementpath: delegates XPath
- XML resource → Instance validation: supplies instances
- Schema construction → Instance validation: validates against graph
- Instance validation → Converter policy: typed traversal
- Converter policy → DataElement bindings: can produce bindings
- Document APIs → Schema construction: wraps
- Schema export → Schema construction: exports resources
- Python binding generation → Schema construction: generates bindings from