Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with base-uri in assertion #379

Closed
sgtraptor opened this issue Jan 8, 2024 · 7 comments
Closed

Problem with base-uri in assertion #379

sgtraptor opened this issue Jan 8, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@sgtraptor
Copy link

Hi,
first of all thanks for 3.0.0 release! Right now we have a problem with validation against assertion that check filename.

$xml_file_path := upper-case(string(base-uri())),

Validate function acts as if there was no filename. Is there any way to set this up so base-uri returns filename properly?

@brunato
Copy link
Member

brunato commented Jan 8, 2024

Hi,

It could be an issue of the XPath processor (elementpath). The function base-uri() returns the base-uri property of the XPath node (if the context item is an XPath node).
Usually this property is related with the presence of a xml:base attribute in the XML data.
I need a chunk of the XML data for reproducing the issue.

thank you

@sgtraptor
Copy link
Author

Hi @brunato,
in archive there is:

  • test.xml - has schemalocation set to xmlschema-test.xsd
  • xmlschema-test.xsd - there is one test that checks if xml's filename is "test"
  • script-test.py - thats a script that we run the validation with

base-uri-test.zip

@brunato
Copy link
Member

brunato commented Jan 8, 2024

A resolution for this will require an enhancement of the XPath processor (maybe an additional argument for DocumentNode class), and then a change in xmlschema.resources.XMLResource.
It could be in a next minor version.

As a workaround until that, you could add a specific xml:base attribute in XML root element, e.g.:

import xmlschema
my_schema = xmlschema.XMLSchema11('xmlschema-test.xsd',use_xpath3=True)
resource = xmlschema.XMLResource('test.xml')
resource.root.attrib['{http://www.w3.org/XML/1998/namespace}base'] = resource.uri
my_schema.validate(resource)

@sgtraptor
Copy link
Author

sgtraptor commented Jan 9, 2024

Thanks for quick reply, but we seem to have a problem with parsing our xsd first (we thought this happens because of base-uri but if we only leave XMLSchema11 we get an error as well), so this happens even before xml is validated. This is XSD is valid because we can validate it with Altova.

`Traceback (most recent call last):
File "/Users/def/Library/Python/3.9/lib/python/site-packages/xmlschema/validators/assertions.py", line 115, in build
self.parse_error(err)
File "/Users/def/Library/Python/3.9/lib/python/site-packages/xmlschema/validators/xsdbase.py", line 194, in parse_error
raise error
xmlschema.validators.exceptions.XMLSchemaParseError: [err:FORG0006] the second argument must be xs:numeric:

Schema component:

<xs:assert xmlns:xs="http://www.w3.org/2001/XMLSchema" test="let $xml_file_path := string(base-uri()), $last_slash_pos := index-of(string-to-codepoints(upper-case(string(base-uri()))), string-to-codepoints('/'))[last()], $xml_file_name := substring($xml_file_path, $last_slash_pos + 1), $schema_file_location := @xsi:noNamespaceSchemaLocation, $schema_last_slash_pos := index-of(string-to-codepoints($schema_file_location), string-to-codepoints('/'))[last()], $schema_name := substring($schema_file_location, $schema_last_slash_pos + 1), $schema_type := substring-before(substring-after(substring-after($schema_name, '.'), '.'), '.'), $schema_type_upper := upper-case($schema_type), $regex_pattern := concat('^', $schema_type_upper, '_.*') return matches($xml_file_name, $regex_pattern)">
xs:annotation
<xs:documentation source="Definition" xml:lang="PL">Typ raportu z nazwy pliku nie zgadza się z typem raportu wybranej XML schema. Typ raportu powinien być określony w nazwie pliku XML wielkimi literami.</xs:documentation>
<xs:documentation source="Name" xml:lang="PL">SPRAWOZDANIE_00001</xs:documentation>
</xs:annotation>
</xs:assert>`

XSD that is causing these problems:
knf.fi.DniWycenyFIZ.zip

@brunato
Copy link
Member

brunato commented Jan 9, 2024

The problem maybe the same and happens during the XPath static analysis. I've no workaround for this, you have to wait for a fix in elementpath package.

@brunato brunato added the bug Something isn't working label Jan 12, 2024
@brunato
Copy link
Member

brunato commented Feb 19, 2024

Hi,
the latest version (v3.0.2) should process the assertions of knf.fi.DniWycenyFIZ schema. The schema analysis in elementpath has been changed so many errors are not considered anymore during this phase (see the release notes), so the assertions parsing do not fails anymore.

Probably there could be other thing to adjust on this, also for assertion dynamic evaluation on XML data, so I wait for your feedback on XML validation cases.

@brunato
Copy link
Member

brunato commented Sep 19, 2024

Seem to be fine now, if not re-open this issue.

@brunato brunato closed this as completed Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants