Project

Profile

Help

Should browser side HTMLDocument allow XPath element selection without explicitly setting up the XHTML namespace as xpathDefaultNamespace?

Added by Martin Honnen over 4 years ago

Inside the browser most browsers nowadays support parsing a snippet of HTML into a HTML DOM document with new DOMParser().parseFromString(htmlString, 'text/html') e.g. with

const htmlDoc = new DOMParser().parseFromString(`<hr>
<center>
<a href="http://www.somewebsite.html" target="_blank">Description</a>
</center>
<br>
SEC 10 TWP 20 RGE 30
<br>
PLAT BOOK A PAGE 200
<br>
BLK 10 LOTS 1.4.5.6.7.8. EX
<br>
POSSIBLY MORE TEXT...
<br>
<hr>`, 'text/html');

I had expected that SaxonJS.XPath.evaluate('//center', htmlDoc) selects the center element with Saxon JS 2 in the browser but I have to use SaxonJS.XPath.evaluate('//center', htmlDoc, { xpathDefaultNamespace : 'http://www.w3.org/1999/html' }) explicitly to make this work.

Aren't HTMLDocuments supposed to work out of the box with the XHTML namespace assumed to be the XPath default namespace?


Please register to reply