Bug #5944
closedset_cwd on PySchemaValidator seems to be ignored when registering schema with relative xsd_file name argument or validating file_name with relative file name
100%
Description
Using SaxonC EE 12.1 under both Windows and Linux it seems using set_cwd on an PySchemaValidator doesn't have to be any effect on the subsequent use of e.g. validator.register_schema(xsd_file='schema2.xsd')
or validator.validate(file_name=
as the error message I then get suggest the file is looked for in the current working directory the Python file is called from but not the one set with set_cwd
.
Examples: my failing PHP code does e.g.
from pathlib import Path
from saxoncee import *
with PySaxonProcessor(license=True) as saxon_processor:
print(saxon_processor.version)
validator = saxon_processor.new_schema_validator()
input_path = Path.cwd() / '..' / 'test-schemas'
input_path = str(input_path.resolve())
print(input_path)
validator.set_cwd(input_path)
try:
validator.register_schema(xsd_file='schema2.xsd')
validator.validate(file_name='sample2-well-formed-invalid.xml')
print('XML is valid.')
except RuntimeError as e:
print(f'Validation failed: {e}')
and the output then is e.g.
(saxonc-12.1-validatation-test1) mh@LibertyDell:~/saxonc-12.1-validatation-test1$ pwd
/home/mh/saxonc-12.1-validatation-test1
(saxonc-12.1-validatation-test1) mh@LibertyDell:~/saxonc-12.1-validatation-test1$ python test-invalid-sample2.py
SaxonC-EE 12.1 from Saxonica
/home/mh/test-schemas
Validation failed: java.io.FileNotFoundException: /home/mh/saxonc-12.1-validatation-test1/schema2.xsd (No such file or directory). Line number: -1
so while I set cwd to e.g. /home/mh/test-schemas
the file schema2.xsd
is looked for in the working directory /home/mh/saxonc-12.1-validatation-test1
the python file is called in.
Putting the schema in the working directory the Python file is called from works as it does work to not rely on set_cwd
and have explicit paths on the individual arguments e.g.
validator.register_schema(xsd_file=str(Path.cwd() / '..' / 'test-schemas' / 'schema2.xsd'))
validator.validate(file_name=str(Path.cwd() / '..' / 'test-schemas' / 'sample2-well-formed-invalid.xml'))
but I wonder what is the point of having the set_cwd
method.
Files
Please register to edit this issue