Using XPathResult

I find a little XPathResult documentation on the mozilla development site. All of the listed functions are redirected to the main page, so they are probably not registered yet.

var myFind;
myFind = document.evaluate(
    '/html/body/table[1]',
    document,
    null,
    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
    null);

I am looking for a way to notify the HTML tree that is under the specified path.

Usage alert(myFind);does not work, it just gives "XPathResult". There is only a corpse and a bunch of tr elements under it, and I would like to see them all in the warning as 1 line.

What function can myFind use for this?

+4
source share
1 answer
var myFind;
myFind = document.evaluate(
    '/html/body/table[1]',
    document,
    null,
    XPathResult.FIRST_ORDERED_NODE_TYPE,
    null);

var node = myFind.singleNodeValue;

I use FIRST_ORDERED_NODE_TYPEbecause you are looking for only one table. singleNodeValueallows you to extract the node.

node HTML DOM Node. , node, . serializeToString:

new XMLSerializer().serializeToString(node)

XPath XPathResult .

+5

All Articles