1

I've created a RELAX NG schema document and an XML instance document that conforms to this schema. I'm using the python lxml library to parse and validate the files.

I'm looking into using the lxml.objectify API and followed the examples here more or less without problems until I reached the "Asserting a Schema" section.

I see that in the example it uses an etree.XMLSchema type but I think/thought/hope that I somehow could pass an etree.RelaxNG type too, but alas:

relaxng_doc = etree.parse('schema/link.rng')
relaxng = etree.RelaxNG(relaxng_doc)
parser = objectify.makeparser(schema = relaxng)

Gives me:

Traceback (most recent call last):
File "C:\Users\rubin\Source\Projects\Even\even.py", line 26, in <module>
parser = objectify.makeparser(schema = relaxng)
File "lxml.objectify.pyx", line 1801, in lxml.objectify.makeparser  (src/lxml\lxml.objectify.c:19114)
File "parser.pxi", line 1261, in lxml.etree.XMLParser.__init__ (src/lxml\lxml.etree.c:80303)
TypeError: Argument 'schema' has incorrect type (expected lxml.etree.XMLSchema, got lxml.etree.RelaxNG)

I'm still quite new to this stuff so before I start to accept that lxml.objectify's makeparser can only use a W3C XML Schema 1.0 xsd parser, I thought I'd ask here: Am I correct that the lxml.objectify API can only validate using W3C XML Schema, and not with RELAX NG schema?

Rubin Simons
  • 1,556
  • 1
  • 13
  • 20
  • 1
    Why don't you use `relaxng.validate(xml)`? –  Sep 11 '12 at 08:42
  • I know that that's possible, in that case one would split validation and actual attribute value instantiation into two separate steps, which is fine too of course; I just want to know if it's really true that lxml.objectify's makeparser only works with W3C XML Schema. – Rubin Simons Sep 11 '12 at 09:03
  • possible duplicate of [How do I validate XML document using RELAX NG schema in Python?](http://stackoverflow.com/questions/1254919/how-do-i-validate-xml-document-using-relax-ng-schema-in-python) – Paul Sweatte Jun 19 '14 at 22:35

0 Answers0