I’m finding little documentation on XPathResult on the mozilla developper site. All functions listed redirect to the main page, so they’re probably not documented yet.
var myFind;
myFind = document.evaluate(
'/html/body/table[1]',
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null);
I’m looking for a way to alert the HTML tree that is under the path given.
Using alert(myFind); doesn’t work, it just gives “XPathResult”.
There’s just a tbody and a bunch of tr elements beneath it, and I’d like to see them all in an alert as 1 string.
What function can myFind use to do this?
I’m using
FIRST_ORDERED_NODE_TYPEbecause you’re only looking for a single table.singleNodeValuelets you extract the node.Now node is a regular HTML DOM Node. You can serialize it the same way as any other node, e.g. with serializeToString:
You may find Using XPath and XPathResult helpful.