Skip to main content

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.

Usage

import glob
from acdh_xml_validator import Validator


validator = Validator(
    path_to_rng="test/schemata/tillich-briefe.rng",
    path_to_schematon="test/schemata/tillich-schematron.sch"
)

files = glob.glob("test/xmls/*.xml")

for x in files:
    valid = validator.validate(x)

result:

test/xmls/L00003.xml is not valid according to test/schemata/tillich-briefe.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

acdh_xml_validator-0.1.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

acdh_xml_validator-0.1.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file acdh_xml_validator-0.1.0.tar.gz.

File metadata

  • Download URL: acdh_xml_validator-0.1.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.0

File hashes

Hashes for acdh_xml_validator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e21dbb01111bce18b938e26cfea5016bfe9de743f44baabfbc350ffda0eb2bc2
MD5 ce1463d083143c932545fbccd0d90d03
BLAKE2b-256 4554e27ee49aa6449de7ddf41d0b8ac7d89a44c24b24611f8674b3335775a65d

See more details on using hashes here.

File details

Details for the file acdh_xml_validator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for acdh_xml_validator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d36518b47dccef446b66e4b62929f3f8135d3c6d930b326b944af53e5ab55b7
MD5 2d116233dd15edc2c8e03fae00072441
BLAKE2b-256 b0db5e1b70d32205ae4906d5b399102d3afadb53b8eb2f0a47316066649b0093

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page