Skip to content

paulschell/xsdflatten

 
 

Repository files navigation

xsdflatten

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.

Installation

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)

lxml "troubleshooting"

# 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 lxml

Install directly from source:

pip3 install .

Or for development:

pip3 install -e .

After installation, you can use the xsdflatten command directly.

Dependencies

If installing manually, install dependencies using:

pip3 install -r requirements.txt

Usage

After installation via pip:

xsdflatten input_schema.xsd
xsdflatten --output flattened.xsd input_schema.xsd

Or run directly without installation:

python3 xsdflatten.py input_schema.xsd
python3 xsdflatten.py --output flattened.xsd input_schema.xsd

Or run by venv:

# 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.xsd

Options

  • input_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 >.

Example - example.sh (wholesome example)

Run example.sh:

What does the script do:

  • 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.sh

The script will produce the flattened xsd file: example/ONIX_BookProduct_3.1_reference_flattened.xsd

Attribution

  • 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.

About

Rudimentary python script to flatten an xsd schema into a single document

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 93.2%
  • Shell 6.8%