sissaschool / xmlschema

XML Schema validator and data conversion library for Python
MIT License
423 stars 72 forks source link

schematron #286

Open robbert-harms opened 2 years ago

robbert-harms commented 2 years ago

Hi all,

I was wondering, would it be possible to extend or amend XMLSchema such that it can validate XML files using Schematron? I know lxml has some support for this, but this does not allow for using xslt2.0.

This ticket is a long shot and you are all probably very busy with other stuff, but I thought let's try anyway.

Best,

Robbert

brunato commented 2 years ago

Hi, extending couldn't be an option because XMLSchema and Schematron don't have nothing in common (as i remember, conversely Relax NG uses XSD datatypes and it could have more sense).

Assertions are essentaly based on the XPath processor (elementpath), and probably it can be reused also for building XPath proxies for processing Schematron assertions.

Probably for this it could be implemented in an optional subpackage with a help from other contributors. Also better to know before which is the lxml roadmap for XLST 2.0 (and maybe other features, like XPath 2.0).

So I leave this open with an enhancement label for the moment.

Best

Davide

robbert-harms commented 2 years ago

Hi Davide,

Thank you for your response. I am aware that Schematron and XSD are orthogonal instruments. The common ground is indeed the need of an XPath processor.

A separate package, or a subpackage might be the goal here.

Thanks for holding it under consideration. Let's see what the community thinks of this.

Best,

Robbert

martin-honnen commented 1 year ago

@robbert-harms , in the Python world you now have an option to use Schematron with XPath 2 and later if you use Saxonica's saxonche package https://pypi.org/project/saxonche/ together with your favourite XSLT based implementation of Schematron (i.e. usually the ISO Schematron XSLT 2.0 implementation or the newer Schxslt by David Maus). Not related to the XmlSchema library and not a pure Python package but at least an option to have a PyPi package to perform Schematron based validation with XPath 2 or later tests/assertions.

robbert-harms commented 1 year ago

Hi @martin-honnen,

Thanks for your comment. I am aware of the saxonche project, it is a very nice package. I still wanted something Python based and for that I have been working on this package: https://github.com/robbert-harms/pyschematron .

It is not complete yet, but when finished it will be a pure Python package build on top of the excellent elementpath library from @brunato. The parsing is done, the query binding is done, it is only pending the last step of executing the validation. It is a hobby project, expect it to be finished around summer.

Best,

Robbert