Incorrect result when running the same xpath against a similar document
See original GitHub issueSee below example test.
const nameSpaceDocument = new slimdom.Document();
const namespaceElement = nameSpaceDocument.createElementNS("http://test.com", "name");
namespaceElement.textContent = 'name1'
nameSpaceDocument.appendChild(namespaceElement);
chai.assert.equal(evaluateXPathToString('/name/text()', nameSpaceDocument), 'name1')
const slimdomDocument = new slimdom.Document();
const nameElement = slimdomDocument.createElement("name");
nameElement.textContent = 'name2'
slimdomDocument.appendChild(nameElement);
chai.assert.equal(evaluateXPathToString('/name/text()', slimdomDocument), 'name2')
The first document includes a namespace on the name element. The second document does not. The second assertion will fail, however if you change the order of the assertions it works as expected. If you change the second xpath to just be ‘/name’ it also works as expected. Looks to be a caching issue?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Failed to execute 'evaluate' on 'Document' error using XPath ...
no such element: Unable to locate element is a different error from your initial SyntaxError which seems to have got resolved now. Feel...
Read more >Complete Guide For Using XPath In Selenium With Examples
XPath in Selenium allows you to run queries against localized documents even if they don't share the same base tag name. How do...
Read more >Introduction to using XPath in JavaScript - MDN Web Docs
This method evaluates XPath expressions against an XML based document (including HTML documents), and returns a XPathResult object, which can be ...
Read more >Xpath syntax error when I use `contains` for `classname` and ...
To achieve this I am trying something like this: ... following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string ...
Read more >XPath and XQuery Functions and Operators 3.1 - W3C
This section is concerned with the question of whether two calls on a function, with the same arguments, may produce different results. [ ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Found it, when compiling an expression, we try to return a fully cached expression if both the expression string the static contexts match another run. This fails here. We then try to get a ‘half compiled’ result, which can occur when someone just asked for a bucket of a selector, but did not execute it. Getting the bucket of a selector does not require static compilation, but does require a ‘normal’ compilation. However, this mistakingly gets any compilation result. See https://github.com/FontoXML/fontoxpath/blob/master/src/parsing/compiledExpressionCache.ts#L129, which in the end does https://github.com/FontoXML/fontoxpath/blob/master/src/parsing/compiledExpressionCache.ts#L46.
The fix would be to only use the ‘halfcompiled’ cache here.
Hi, Yes it is now working as expected. Thanks for the quick turnaround!