Forum Bugs

document.evaluate() throwing TypeError: undefined value is not an object

jrintaha
Any call to document.evaluate() throws a TypeError, for example:

var h1_iter = document.evaluate("//h1", document, null, XPathResult.ANY_TYPE, null);

I use a couple of XPath queries to build a table of contents for a rather heterogeneous document parsed together from different sources, so they come in handy there. The obvious workaround is not to use document.evaluate() and traverse the document tree manually instead - or pre-render the the entire HTML file and use Prince with that - but is there any other workaround?

The same issue happens with both the official Prince 10 Windows release and the "alpha" release in http://www.princexml.com/latest/.

Cheers,
Jori Rintahaka / Silicon Labs
mikeday
Prince does not support XPath at this time.

Perhaps you could try wicked-good-xpath, a JavaScript implementation (polyfill) of document.evaluate?
jrintaha
Thanks for the prompt reply. This was exactly what I was looking for - it silently replaces the document.evaluate() function with one that works with Prince.

I didn't notice the documentation saying anywhere that XPath is not supported, so it might be a good idea to put a small note there somewhere, and perhaps point users needing it to wicked-good-xpath.

Cheers,
Jori Rintahaka / Silicon Labs
mikeday
Yes, unfortunately we don't document every unsupported feature, as we don't always realise a feature exists; I didn't know browsers supported XPath by default now. :)