isoschematron RELAXNG validation faulty

Bug #1467503 reported by Weyland
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
Invalid
Undecided
Unassigned

Bug Description

We're trying to create a validator from a Schematron schema. The schema is valid; it works with oXygen XML and several other non-Python implementations we've tried. However, lxml gives us this RELAXNG error:

lxml.etree.SchematronParseError: invalid schematron schema: <string>:597:0:ERROR:RELAXNGV:RELAXNG_ERR_NOELEM: Expecting an element , got nothing
<string>:0:0:ERROR:RELAXNGV:RELAXNG_ERR_INTEREXTRA: Extra element rule in interleave
<string>:597:0:ERROR:RELAXNGV:RELAXNG_ERR_CONTENTVALID: Element pattern failed to validate content
<string>:308:0:ERROR:RELAXNGV:RELAXNG_ERR_ELEMNAME: Expecting element p, got pattern
<string>:0:0:ERROR:RELAXNGV:RELAXNG_ERR_INTEREXTRA: Extra element pattern in interleave
<string>:596:0:ERROR:RELAXNGV:RELAXNG_ERR_CONTENTVALID: Element schema failed to validate content

Here is the XML in question:

  <sch:pattern id="p-oid-2.16.840.1.113883.10.20.22.4.25-errors">
    <sch:rule id="r-oid-2.16.840.1.113883.10.20.22.4.25-errors-abstract" abstract="true" />
    <sch:rule id="r-oid-2.16.840.1.113883.10.20.22.4.25-errors" context="cda:criterion[cda:templateId[@root='2.16.840.1.113883.10.20.22.4.25']]">
      <sch:extends rule="r-oid-2.16.840.1.113883.10.20.22.4.25-errors-abstract" />
      <sch:assert id="a-81-7372" test="count(cda:templateId[@root='2.16.840.1.113883.10.20.22.4.25'])=1">SHALL contain exactly one [1..1] templateId (CONF:7372) such that it SHALL contain exactly one [1..1] @root="2.16.840.1.113883.10.20.22.4.25" (CONF:10517).</sch:assert>
    </sch:rule>
  </sch:pattern>

from the QRDA Category I schema.

Other useful info:
Python 2.7.6
lxml 3.4.4
libxml 2.9.0
libxslt 1.1.28

Please contact me at <email address hidden> for more info on the error. Thanks!

Revision history for this message
scoder (scoder) wrote : Re: [Bug 1467503] [NEW] isoschematron RELAXNG validation faulty

Please try to reproduce your problem with the xmllint command line tool
that comes with libxml2. If that fails as well (and it most likely will)
this is not a problem in lxml but in libxml2.

That being said, have you tried the implementation in lxml's isoschematron
package? It uses the XSLT based reference implementation of Schematron and
should therefore be as compliant as it gets.

Revision history for this message
Weyland (weyland-5) wrote :
Download full text (3.3 KiB)

The step that fails with xmllint is the RELAXNG validation step: xmllint
--noout --relaxng iso-schematron.rng schema.sch.

This is the same step that seems to fail when constructing a validator
using lxml's implementation (particularly lines 66-67 and 276-279 of
isoschematron/__init__.py).

Assuming the Schematron schema is valid, this means there must be a problem
with the RELAXNG used to parse it:
schematron_schema_valid =
_etree.RelaxNG(_etree.parse(os.path.join(_resources_dir, 'rng',
'iso-schematron.rng')))

If that iso-schematron.rng is coming from libxml2, then you're right, it's
a libxml2 problem.

On Mon, Jun 22, 2015 at 12:20 PM, scoder <email address hidden> wrote:

> Please try to reproduce your problem with the xmllint command line tool
> that comes with libxml2. If that fails as well (and it most likely will)
> this is not a problem in lxml but in libxml2.
>
> That being said, have you tried the implementation in lxml's isoschematron
> package? It uses the XSLT based reference implementation of Schematron and
> should therefore be as compliant as it gets.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1467503
>
> Title:
> isoschematron RELAXNG validation faulty
>
> Status in lxml - the Python XML toolkit:
> New
>
> Bug description:
> We're trying to create a validator from a Schematron schema. The
> schema is valid; it works with oXygen XML and several other non-Python
> implementations we've tried. However, lxml gives us this RELAXNG
> error:
>
> lxml.etree.SchematronParseError: invalid schematron schema:
> <string>:597:0:ERROR:RELAXNGV:RELAXNG_ERR_NOELEM: Expecting an element ,
> got nothing
> <string>:0:0:ERROR:RELAXNGV:RELAXNG_ERR_INTEREXTRA: Extra element rule
> in interleave
> <string>:597:0:ERROR:RELAXNGV:RELAXNG_ERR_CONTENTVALID: Element pattern
> failed to validate content
> <string>:308:0:ERROR:RELAXNGV:RELAXNG_ERR_ELEMNAME: Expecting element p,
> got pattern
> <string>:0:0:ERROR:RELAXNGV:RELAXNG_ERR_INTEREXTRA: Extra element
> pattern in interleave
> <string>:596:0:ERROR:RELAXNGV:RELAXNG_ERR_CONTENTVALID: Element schema
> failed to validate content
>
> Here is the XML in question:
>
> <sch:pattern id="p-oid-2.16.840.1.113883.10.20.22.4.25-errors">
> <sch:rule id="r-oid-2.16.840.1.113883.10.20.22.4.25-errors-abstract"
> abstract="true" />
> <sch:rule id="r-oid-2.16.840.1.113883.10.20.22.4.25-errors"
> context="cda:criterion[cda:templateId[@root='2.16.840.1.113883.10.20.22.4.25']]">
> <sch:extends
> rule="r-oid-2.16.840.1.113883.10.20.22.4.25-errors-abstract" />
> <sch:assert id="a-81-7372"
> test="count(cda:templateId[@root='2.16.840.1.113883.10.20.22.4.25'])=1">SHALL
> contain exactly one [1..1] templateId (CONF:7372) such that it SHALL
> contain exactly one [1..1] @root="2.16.840.1.113883.10.20.22.4.25"
> (CONF:10517).</sch:assert>
> </sch:rule>
> </sch:pattern>
>
> from the QRDA Category I schema.
>
> Other useful info:
> Python 2.7.6
> lxml 3.4.4
> libxml 2.9.0
> libxslt 1.1.28
>
> Please contact me at <email address hidden> for more info on
> ...

Read more...

Revision history for this message
Weyland (weyland-5) wrote :

If you can confirm that the iso-schematron.rng in question come from
libxml2, then I'll file a report with them.

Thanks for your help.

On Mon, Jun 22, 2015 at 12:20 PM, scoder <email address hidden> wrote:

> Please try to reproduce your problem with the xmllint command line tool
> that comes with libxml2. If that fails as well (and it most likely will)
> this is not a problem in lxml but in libxml2.
>
> That being said, have you tried the implementation in lxml's isoschematron
> package? It uses the XSLT based reference implementation of Schematron and
> should therefore be as compliant as it gets.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1467503
>
> Title:
> isoschematron RELAXNG validation faulty
>
> Status in lxml - the Python XML toolkit:
> New
>
> Bug description:
> We're trying to create a validator from a Schematron schema. The
> schema is valid; it works with oXygen XML and several other non-Python
> implementations we've tried. However, lxml gives us this RELAXNG
> error:
>
> lxml.etree.SchematronParseError: invalid schematron schema:
> <string>:597:0:ERROR:RELAXNGV:RELAXNG_ERR_NOELEM: Expecting an element ,
> got nothing
> <string>:0:0:ERROR:RELAXNGV:RELAXNG_ERR_INTEREXTRA: Extra element rule
> in interleave
> <string>:597:0:ERROR:RELAXNGV:RELAXNG_ERR_CONTENTVALID: Element pattern
> failed to validate content
> <string>:308:0:ERROR:RELAXNGV:RELAXNG_ERR_ELEMNAME: Expecting element p,
> got pattern
> <string>:0:0:ERROR:RELAXNGV:RELAXNG_ERR_INTEREXTRA: Extra element
> pattern in interleave
> <string>:596:0:ERROR:RELAXNGV:RELAXNG_ERR_CONTENTVALID: Element schema
> failed to validate content
>
> Here is the XML in question:
>
> <sch:pattern id="p-oid-2.16.840.1.113883.10.20.22.4.25-errors">
> <sch:rule id="r-oid-2.16.840.1.113883.10.20.22.4.25-errors-abstract"
> abstract="true" />
> <sch:rule id="r-oid-2.16.840.1.113883.10.20.22.4.25-errors"
> context="cda:criterion[cda:templateId[@root='2.16.840.1.113883.10.20.22.4.25']]">
> <sch:extends
> rule="r-oid-2.16.840.1.113883.10.20.22.4.25-errors-abstract" />
> <sch:assert id="a-81-7372"
> test="count(cda:templateId[@root='2.16.840.1.113883.10.20.22.4.25'])=1">SHALL
> contain exactly one [1..1] templateId (CONF:7372) such that it SHALL
> contain exactly one [1..1] @root="2.16.840.1.113883.10.20.22.4.25"
> (CONF:10517).</sch:assert>
> </sch:rule>
> </sch:pattern>
>
> from the QRDA Category I schema.
>
> Other useful info:
> Python 2.7.6
> lxml 3.4.4
> libxml 2.9.0
> libxslt 1.1.28
>
> Please contact me at <email address hidden> for more info on
> the error. Thanks!
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/lxml/+bug/1467503/+subscriptions
>

Revision history for this message
scoder (scoder) wrote :

Ok, so you *are* using the ISO Schematron implementation. :) (sorry, should
have read the ticket title more carefully...)

That code actually comes from here:

http://www.schematron.com/

Specifically, the RelaxNG schema is based on this one:

http://www.schematron.com/iso/iso-schematron.rnc

Please try it with a different RelaxNG engine to make sure it's not just a
problem in libxml2's RelaxNG implementation.

If the validation fails with other validators, too, then it means that your
schema file is not a valid Schematron document. If you then still think it
really is valid, and that the reference schema for Schematron is wrong, you
can try to contact the author, Rick Jelliffe, and discuss the matter with him.

If the validation works with other RelaxNG engines and only libxml2/lxml
fail, then it's probably a problem in libxml2's RelaxNG implementation, and
that project is the right place to report the bug.

Also try commenting out the validation part in isoschematron/__init__.py
and see if the validation is the only problem or if the actual evaluation
of the schema then also fails.

Revision history for this message
scoder (scoder) wrote :

Closing: not a problem in lxml itself.

Changed in lxml:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.