Use this Python script to recursively download an XML schema (XSD) and all linked schemas. This lets you quickly validate an xml record using a tool such as xmllint
.
It supports relative XSD schemaLocations, eg <import schemaLocation="../../../../abc
.
If needed, install virtualenv
. Install repo in a new Python 3 environment:
pip install venv --user
python -m venv venv
source venv/bin/activate
pip install .
Run the script with your favorite .xsd URL:
python -m xsd_download https://schemas.isotc211.org/19115/-3/mdb/2.0/mdb.xsd
Your schema ends up in a folder called 'xsd'
Then if you have xmllint
installed, you can validate an XML file called myrecord.xml
by running:
xmllint --noout --schema ./xsd/schemas.isotc211.org/19115/-3/mdb/2.0/mdb.xsd myrecord.xml
python tests/tests.py
You can create a Docker image containing the script. This way you don't need to setup any python and venv.
docker build -t cioos-siooc/xml-schema-downloader:1.0 .
Run the image with your favorite .xsd URL:
docker run --rm -v `pwd`:`pwd` -w `pwd` cioos-siooc/xml-schema-downloader:1.0 https://schemas.isotc211.org/19115/-3/mdb/2.0/mdb.xsd