A python package to validate XML file using against custom schema and schematron files.
Project description
acdh-xml-validator
A Python package for validating XML files against RelaxNG and Schematron schemas. This module provides a Validator class that can validate XML documents using both RelaxNG (.rng) and Schematron (.sch) schemas, particularly useful for TEI (Text Encoding Initiative) XML documents.
Installation
pip install acdh-xml-validator
or
uv add acdh-xml-validator`
Usage (CLI)
RNG and Schematron
uv run validate-all --files "data/editions/*.xml" --rng "schemata/rng.rng" --schematron "schemata/schematron.sch"
RNG
uv run validate-rng --files "data/editions/*.xml" --rng "schemata/rng.rng"
SCHEMATRON
uv run validate-schematron --files "data/editions/*.xml" --schematron "schemata/schematron.sch"
Usage (Python)
import glob
from acdh_xml_validator import Validator
validator = Validator(
path_to_rng="schemata/rng.rng",
path_to_schematon="schemata/schematron.sch"
)
files = glob.glob("data/editions/*.xml")
for x in files:
valid = validator.validate(x)
result:
test/xmls/L00003.xml is not valid according to test/schemata/rng.rng schema
- test/xmls/L00003.xml:120:0:ERROR:RELAXNGV:RELAXNG_ERR_ELEMNAME: Expecting element idno, got rs
- test/xmls/L00003.xml:119:0:ERROR:RELAXNGV:RELAXNG_ERR_ELEMNAME: Expecting element dateline, got signed
- test/xmls/L00003.xml:119:0:ERROR:RELAXNGV:RELAXNG_ERR_ELEMWRONG: Did not expect element signed there
- test/xmls/L00003.xml:87:0:ERROR:RELAXNGV:RELAXNG_ERR_ELEMWRONG: Did not expect element p there
- test/xmls/L00003.xml:119:0:ERROR:RELAXNGV:RELAXNG_ERR_EXTRACONTENT: Element div has extra content: closer
- test/xmls/L00003.xml:79:0:ERROR:RELAXNGV:RELAXNG_ERR_CONTENTVALID: Element text failed to validate content
test/xmls/L00107.xml is not valid according to test/schemata/tillich-schematron.sch
- The @ref attribute for rs type @bible must start with a captial letter or with a number
- The @ref attribute for rs type @bible must start with a captial letter or with a number
- The @ref attribute for rs type @bible must start with a captial letter or with a number
develop
install the package in editable mode
uv pip install -e .
uv run python
>>> from acdh_xml_validator import hello
>>> hello()
'Hello you from acdh-xml-validator!'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file acdh_xml_validator-1.1.0.tar.gz.
File metadata
- Download URL: acdh_xml_validator-1.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4b901ff51d2975492142b0276d3145e58764baf536005bcd2857ea19bbdab8b
|
|
| MD5 |
b71b47bc6e178b5cbf64172420419595
|
|
| BLAKE2b-256 |
3118b5177de7f8b4b2d21ff9b408c40fd4bfefab16de25b44361187559831a35
|
File details
Details for the file acdh_xml_validator-1.1.0-py3-none-any.whl.
File metadata
- Download URL: acdh_xml_validator-1.1.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
290b8f1a0226ec8433f408b25e6ae28513507e65e2234d2e5b985a921b92d1e7
|
|
| MD5 |
ca802a17c979b1589edc009c78062476
|
|
| BLAKE2b-256 |
4f072c83e008bfce0ba4871274a71c258a3b013950f2f0d0884df9f7ae6680e0
|