What’s the XPath expression to select all elements, text nodes, and ment nodes, in the same order as they appear in the document?
The following effectively selects all elements, but not text nodes and ment 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 ment()');
What’s the XPath expression to select all elements, text nodes, and ment nodes, in the same order as they appear in the document?
The following effectively selects all elements, but not text nodes and ment 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 ment()');
Share
Improve this question
asked May 30, 2012 at 10:59
Mathias BynensMathias Bynens
150k54 gold badges222 silver badges251 bronze badges
2 Answers
Reset to default 5//node()
selects every node that is a child of something: i.e all elements, text nodes, ments, and processing instructions (but not attributes, namespace nodes, or the document node)
Tested with text and ment nodes in an XML document. There may be a more efficient approach, but this returns elements, text and ment nodes in document order for me, using union:
//*|//*/text()|//*/ment()
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745096712a4611023.html
评论列表(0条)