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

Selecting multiple NamespaceNodes throws 'Unexpected: could not determine node order' #83

Closed
marklagendijk opened this issue Mar 15, 2018 · 1 comment

Comments

@marklagendijk
Copy link

const xpath = require('xpath');
const DOMParser = require('xmldom').DOMParser;

const xml = '<book xmlns:book1="http://example.com/book1" xmlns:book2="http://example.com/book2"><title>Harry Potter</title></book>';
const document = new DOMParser().parseFromString(xml);
const nodes = xpath.select('/*/namespace::*', document);

console.log(nodes[0].localName + ': ' + nodes[0].firstChild.data);
console.log('Node: ' + nodes[0].toString());

Throws

Error: Unexpected: could not determine node order
    at nodeOrder (/test/node_modules/xpath/xpath.js:3021:11)
    at AVLTree.add (/test/node_modules/xpath/xpath.js:3029:10)
    at XNodeSet.buildTree (/test/node_modules/xpath/xpath.js:3147:23)
    at XNodeSet.toArray (/test/node_modules/xpath/xpath.js:3188:23)
    at new XPathResult (/test/node_modules/xpath/xpath.js:4391:20)
    at XPathExpression.evaluate (/test/node_modules/xpath/xpath.js:4316:9)
    at Object.exports.selectWithResolver (/test/node_modules/xpath/xpath.js:4738:26)
    at Object.exports.select (/test/node_modules/xpath/xpath.js:4718:17)
    at Object.<anonymous> (/test/test.js:6:21)
    at Module._compile (module.js:652:30)

The issue is that the function nodeOrder is not able to determine in which order it should return multiple NamespaceNodes, and therefore throws an Error.

@marklagendijk marklagendijk changed the title Selecting Namespaces throws 'Unexpected: could not determine node order' Selecting multiple NamespaceNodes throws 'Unexpected: could not determine node order' Mar 15, 2018
JLRishe added a commit that referenced this issue Dec 16, 2023
Fix issues with node position and namespace nodes Fixes #135 and #83
@JLRishe
Copy link
Collaborator

JLRishe commented Dec 16, 2023

I'm sorry that it has taken so long to fix this and I imagine the fix is probably no longer relevant to you, but it is fixed now in version 0.0.34. Thank you for reporting it.

@JLRishe JLRishe closed this as completed Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants