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

XMLHelper.getPathToNode returns incorrect position number #31

Closed
bertrand-lorentz opened this issue Nov 15, 2022 · 5 comments
Closed

XMLHelper.getPathToNode returns incorrect position number #31

bertrand-lorentz opened this issue Nov 15, 2022 · 5 comments
Assignees
Labels

Comments

@bertrand-lorentz
Copy link

In XMLHelper.getPathToNode, if a node that is part of the path has one or more siblings with the same name, the path returned indicates the position of the node : /a/b[2]/c

But the position number seems to be off by one. For example, if the node is the first sibling, the position will be 0.
But with XPath, position numbers start at 1

This is visible in the unit test at https://github.com/phax/ph-commons/blob/master/ph-xml/src/test/java/com/helger/xml/XMLHelperTest.java#L319
The node passed to XMLHelper.getPathToNode is the second occurrence of "e1" : //e1[2]
But the location returned indicates it as .../e1[1]

This also affects XMLHelper.getPathToNode2, and this in turn affects ph-schematron in pure mode: the location attribute for failed-assert in SVRL validation reports is off by one.

If this is indeed an issue and not the intended behavior, I can submit a pull request to correct this.

@phax phax self-assigned this Nov 15, 2022
@phax phax added the bug label Nov 15, 2022
@phax
Copy link
Owner

phax commented Nov 15, 2022

Hi @bertrand-lorentz thanks for pointing that out. This is indeed an issue.

That is of course an issue. I will investigate that further and see how to resolve this as backwards compatible as possible.

I assume you refer to the usage in PSXPathValidationHandlerSVRL._getPathToNode - correct?

@bertrand-lorentz
Copy link
Author

Thanks for the quick response.

I assume you refer to the usage in PSXPathValidationHandlerSVRL._getPathToNode - correct?

Yes, it's that method that lead me to XMLHelper.getPathToNode2.
Please note I was only looking at the code, I haven't traced or debugged it. But after finding the unit test, I thought it best to file this issue.

phax added a commit that referenced this issue Nov 17, 2022
@phax
Copy link
Owner

phax commented Nov 17, 2022

I heavily increased the "path to node" functionality to also handle attributes and namespaces etc. This is part of the 10.2.2 release

@phax phax closed this as completed Nov 17, 2022
phax added a commit that referenced this issue Nov 17, 2022
@phax
Copy link
Owner

phax commented Nov 17, 2022

@bertrand-lorentz
Copy link
Author

Excellent, I just confirmed that the issue is fixed with ph-schematron 6.3.4.
Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants