Project

Profile

Help

Bug #5944

closed

set_cwd on PySchemaValidator seems to be ignored when registering schema with relative xsd_file name argument or validating file_name with relative file name

Added by Martin Honnen over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Category:
Python API
Start date:
2023-03-29
Due date:
% Done:

100%

Estimated time:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Found in version:
12.1
Fixed in version:
12.2
SaxonC Languages:
SaxonC Platforms:
SaxonC Architecture:

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

validate-set-cwd-failure.zip (1.26 KB) validate-set-cwd-failure.zip Martin Honnen, 2023-03-29 15:30

Please register to edit this issue

Also available in: Atom PDF