# sissaschool/xmlschema architecture

> Architecture diagram of the GitHub repository sissaschool/xmlschema, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sissaschool/xmlschema
- Repository: https://github.com/sissaschool/xmlschema

## Overview

#### 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: [`xmlschema/validators/schemas.py`](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/validators/schemas.py) (Schema construction), [`xmlschema/resources/xml_resource.py`](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/resources/xml_resource.py) (XML resource), [`xmlschema/validators/validation.py`](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/validators/validation.py) (Instance validation), [`xmlschema/__init__.py`](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/__init__.py) (Package API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public interfaces"]
  node_package_api["Package API<br/>Python exports<br/>[__init__.py]"]
  node_cli["CLI<br/>command entry point<br/>[cli.py]"]
end

subgraph group_schema["Schema core"]
  node_schemas["Schema construction<br/>XSD schemas<br/>[schemas.py]"]
  node_schema_base["Schema contracts<br/>validator base<br/>[xsdbase.py]"]
  node_declarations["XSD declarations<br/>elements, types, groups<br/>[elements.py]"]
  node_validation["Instance validation<br/>validation runtime<br/>[validation.py]"]
  node_namespaces["Names and namespaces<br/>QName normalization<br/>[namespaces.py]"]
  node_xpath["Schema XPath<br/>XPath integration<br/>[mixin.py]"]
end

subgraph group_resources["Resource boundary"]
  node_resource["XML resource<br/>input abstraction<br/>[xml_resource.py]"]
  node_loader["Protected XML loader<br/>secure parser boundary<br/>[xml_loader.py]"]
  node_fetchers["Fetch and locations<br/>URI resolution<br/>[fetchers.py]"]
  node_bundled_xsd["Bundled standards<br/>offline XSDs<br/>[XMLSchema.xsd]"]
end

subgraph group_binding["Data binding"]
  node_converters["Converter policy<br/>data conversion base<br/>[base.py]"]
  node_dataobjects["DataElement bindings<br/>object binding<br/>[dataobjects.py]"]
end

subgraph group_extensions["Higher-level features"]
  node_documents["Document APIs<br/>convenience API<br/>[documents.py]"]
  node_exports["Schema export<br/>offline materialization<br/>[exports.py]"]
  node_codegen["Python binding generation<br/>optional extension<br/>[codegen.py]"]
end

node_elementpath{{"elementpath<br/>external XPath library"}}
node_elementtree{{"ElementTree<br/>Python XML runtime"}}
node_xml_sources["XML and XSD inputs<br/>files, URLs, streams"]

node_package_api -->|"constructs schemas"| node_schemas
node_cli -->|"uses"| node_package_api
node_xml_sources -->|"opens"| node_resource
node_resource -->|"loads XML"| node_loader
node_loader -->|"parses with"| node_elementtree
node_resource -->|"resolves locations"| node_fetchers
node_fetchers -.->|"uses offline standards"| node_bundled_xsd
node_resource -->|"supplies schema documents"| node_schemas
node_schemas -->|"implements contracts"| node_schema_base
node_schemas -->|"registers components"| node_declarations
node_schemas -->|"normalizes QNames"| node_namespaces
node_schemas -->|"supports assertions"| node_xpath
node_xpath -->|"delegates XPath"| node_elementpath
node_resource -->|"supplies instances"| node_validation
node_schemas -->|"validates against graph"| node_validation
node_validation -->|"typed traversal"| node_converters
node_converters -->|"can produce bindings"| node_dataobjects
node_documents -->|"wraps"| node_schemas
node_exports -->|"exports resources"| node_schemas
node_codegen -->|"generates bindings from"| node_schemas

click node_package_api "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/__init__.py"
click node_cli "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/cli.py"
click node_schemas "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/validators/schemas.py"
click node_schema_base "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/validators/xsdbase.py"
click node_declarations "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/validators/elements.py"
click node_validation "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/validators/validation.py"
click node_namespaces "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/namespaces.py"
click node_xpath "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/xpath/mixin.py"
click node_resource "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/resources/xml_resource.py"
click node_loader "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/resources/xml_loader.py"
click node_fetchers "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/resources/fetchers.py"
click node_bundled_xsd "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/schemas/XSD_1.1/XMLSchema.xsd"
click node_converters "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/converters/base.py"
click node_dataobjects "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/dataobjects.py"
click node_documents "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/documents.py"
click node_exports "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/exports.py"
click node_codegen "https://github.com/sissaschool/xmlschema/blob/master/xmlschema/extras/codegen.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_package_api,node_cli toneBlue
class node_schemas,node_schema_base,node_declarations,node_validation,node_namespaces,node_xpath toneAmber
class node_resource,node_loader,node_fetchers,node_bundled_xsd toneMint
class node_converters,node_dataobjects toneRose
class node_documents,node_exports,node_codegen toneIndigo
class node_elementpath,node_elementtree,node_xml_sources toneNeutral
```

## Components

### Public interfaces

- [Package API](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/__init__.py): Python exports · `xmlschema/__init__.py`
- [CLI](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/cli.py): command entry point · `xmlschema/cli.py`

### Schema core

- [Schema construction](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/validators/schemas.py): XSD schemas · Builds version-specific in-memory schema graphs. · `xmlschema/validators/schemas.py`
- [Schema contracts](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/validators/xsdbase.py): validator base · `xmlschema/validators/xsdbase.py`
- [XSD declarations](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/validators/elements.py): elements, types, groups · `xmlschema/validators/elements.py`
- [Instance validation](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/validators/validation.py): validation runtime · `xmlschema/validators/validation.py`
- [Names and namespaces](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/namespaces.py): QName normalization · `xmlschema/namespaces.py`
- [Schema XPath](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/xpath/mixin.py): XPath integration · `xmlschema/xpath/mixin.py`

### Resource boundary

Protected parsing and URI access.

- [XML resource](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/resources/xml_resource.py): input abstraction · Accepts paths, URLs, streams, strings, and trees. · `xmlschema/resources/xml_resource.py`
- [Protected XML loader](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/resources/xml_loader.py): secure parser boundary · Forbids XML entities before validation. · `xmlschema/resources/xml_loader.py`
- [Fetch and locations](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/resources/fetchers.py): URI resolution · `xmlschema/resources/fetchers.py`
- [Bundled standards](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/schemas/XSD_1.1/XMLSchema.xsd): offline XSDs · `xmlschema/schemas/XSD_1.1/XMLSchema.xsd`

### Data binding

- [Converter policy](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/converters/base.py): data conversion base · `xmlschema/converters/base.py`
- [DataElement bindings](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/dataobjects.py): object binding · `xmlschema/dataobjects.py`

### Higher-level features

- [Document APIs](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/documents.py): convenience API · `xmlschema/documents.py`
- [Schema export](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/exports.py): offline materialization · `xmlschema/exports.py`
- [Python binding generation](https://github.com/sissaschool/xmlschema/blob/master/xmlschema/extras/codegen.py): optional extension · `xmlschema/extras/codegen.py`

### Other components

- **elementpath**: external XPath library
- **ElementTree**: Python XML runtime
- **XML and XSD inputs**: files, URLs, streams

## Connections

- 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
