What’s the XPath expression to select all elements, text nodes, and comment nodes, in the same order as they appear in the document?
The following effectively selects all elements, but not text nodes and comment nodes:
var result = document.evaluate('//*', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null),
index = -1;
while (++index < result.snapshotLength) {
console.log(result.snapshotItem(index));
}
Is it possible to do something like the following? (Note: this is non-functional pseudo-code.)
document.evaluate('//* and text() and comment()');
//node()
selects every node that is a child of something: i.e all elements, text nodes, comments, and processing instructions (but not attributes, namespace nodes, or the document node)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With