Python 3 script to flatten an XSD schema into a single document by merging all included schemas. The flattened schema is printed to the console or can be outputed to a file.
Via venv (optional)
# install python via venv
python -m venv ./venv
# Verify python installation and version
./venv/bin/python --version
./venv/bin/python3 --version
# e.g. Python 3.13.3
# Verify pip installation and version
./venv/bin/pip --version
./venv/bin/pip3 --version
# e.g. pip 25.0.1
./venv/bin/pip install "lxml>=5.3.0,<6.0"lxml possible troubleshooting (previous versions, upgrade, cache)
# if previous versions of lxml exists, try to run the following command
./venv/bin/pip uninstall lxml -y
# install lxml version between 5.3 and 6.0, no cache and upgrade if possible / available
./venv/bin/pip install "lxml>=5.3.0,<6.0" --no-cache-dir --upgrade# Verify lxml installation and version
./venv/bin/pip list
# and, or
./venv/bin/pip show lxmlpip3 install .pip3 install -e .After installation, you can use the xsdflatten command directly.
If installing manually, install dependencies using:
pip3 install -r requirements.txtxsdflatten input_schema.xsd
xsdflatten --output flattened.xsd input_schema.xsdpython3 xsdflatten.py input_schema.xsd
python3 xsdflatten.py --output flattened.xsd input_schema.xsd# run
./venv/bin/python xsdflatten.py schema.xsd -o output_flattened.xsd
# or
./venv/bin/python xsdflatten.py schema.xsd --output output_flattened.xsd
# if you experience errors run with -i flag to get a detailed stacktrace
./venv/bin/python -i xsdflatten.py schema.xsd -o output_flattened.xsd
# or
./venv/bin/python xsdflatten.py schema.xsd --output output_flattened.xsdinput_file- Input XSD file to flatten (required)-o, --output FILE- Output file (if not specified, prints to stdout)-h, --help- Show help message
The script processes the main XSD file and all its includes (recursively), then outputs a single flattened XSD schema. Use -o parameter to save to a file or redirect stdout with >.
- Downloads the official ONIX 3.1 XSDs + codes ZIP file from EDItEUR.
- Extracts contents into a structured onix31 directory.
- Moves files up one level to simplify paths (e.g., example/onix31/ONIX_BookProduct_3.1_reference.xsd).
- Runs the XSD flattening command to generate a single, flattened schema file.
or cat example.sh
# execute example.sh
chmod +x example.sh
./example.sh
# or by
sh example.shThe script will produce the flattened xsd file: example/ONIX_BookProduct_3.1_reference_flattened.xsd
- This project is based on the original tool esunder/xsdflatten and is further developed and extended.
- This project is based on the original tool FZU-AV-CR/xsdflatten and is further developed and extended.