Project

Profile

Help

Can I use a schema pulled over HTTP(S) with the PySchemaValidator?

Added by Martin Honnen over 1 year ago

In the Python API, most functions taking an input seem to allow for a file name or a string input. However, in the world of XSLT and of XSD schemas, you might have documents located on a HTTP server. For XSLT or XQuery, I think I can use PyDocumentBuilder and parse_xml(xml_uri=..) and then pass a PyXdmNode to XSLT or XQuery API.

However, for register_schema, the keyword arguments are only xsd_text|xsd_file.

Is there any way to load/use a schema from a HTTP server (particularly, assuming, it imports and/or includes further files, so that a simple Python based download of the file itself doesn't get me all includes/imports as well)?

What I would like to do is e.g.

   with PySaxonProcessor(license=True) as saxon:
        doc_builder = saxon.new_document_builder()
        xslt30_schema_doc = doc_builder.parse_xml(xml_uri='https://www.w3.org/TR/xslt-30/schema-for-xslt30.xsd')

        xsd11_schema_doc = doc_builder.parse_xml(xml_uri='http://www.w3.org/TR/xmlschema11-1/XMLSchema.xsd')

        validator = saxon.new_schema_validator()

        validator.set_lax(False)

        validator.register_schema(xdm_node=xsd11_schema_doc)

        validator.validate(xdm_node=xslt30_schema_doc)

In that example I would also ideally expect Saxon to pull the files from its built in XmlResolver cache, but I think the doc_builder.parse_xml(xml_uri='https://www.w3.org/TR/xslt-30/schema-for-xslt30.xsd') and doc_builder.parse_xml(xml_uri='http://www.w3.org/TR/xmlschema11-1/XMLSchema.xsd') do that, based on the speed of program execution.

I only lack a way of using the schema for schemas to validate a schema as I don't find a way to pass a PyXdmNode to the PySchemaValidator.


Replies (6)

Please register to reply

RE: Can I use a schema pulled over HTTP(S) with the PySchemaValidator? - Added by Martin Honnen over 1 year ago

Any thoughts on this? API restriction or flaw or have I overlooked a way?

RE: Can I use a schema pulled over HTTP(S) with the PySchemaValidator? - Added by O'Neil Delpratt over 1 year ago

I agree the schema validator should allow for the passing of PyXdmNode.

RE: Can I use a schema pulled over HTTP(S) with the PySchemaValidator? - Added by O'Neil Delpratt over 1 year ago

I would have expected the file_name with http to work too. I will file this as a bug along with the PyXdmNode feature key

RE: Can I use a schema pulled over HTTP(S) with the PySchemaValidator? - Added by O'Neil Delpratt over 1 year ago

I have created the bug issue #5643 to track progress on this issue.

RE: Can I use a schema pulled over HTTP(S) with the PySchemaValidator? - Added by O'Neil Delpratt 11 months ago

The following does work with SaxonC 12.0:

        validator.register_schema(xsd_file='http://www.w3.org/TR/xmlschema11-1/XMLSchema.xsd')

        validator.validate(xsd_file='https://www.w3.org/TR/xslt-30/schema-for-xslt30.xsd')

The passing of xdm_node is still not available. Sorry for the omission.

RE: Can I use a schema pulled over HTTP(S) with the PySchemaValidator? - Added by O'Neil Delpratt 11 months ago

I have added the keyword xsd_node to the register_scheme

    (1-6/6)

    Please register to reply