Is it possible to get XML snippets using XPATH in javascript (evaluate function, Chrome)?
How to do it?
Keep getting errors in every approach I've used.
Here is an example:
var xmlDoc = new DOMParser().parseFromString('<root><foo bar="baz">whatever</foo></root>', 'application/xml');
var xpathResult = xmlDoc.evaluate('//foo[@bar = "baz"]', xmlDoc, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
while ((el = xpathResult.iterateNext()) != null) {
alert(el.textContent);
}
Works fine for me with Firefox and Chrome.
evaluate, for Mozilla browsers see developer.mozilla.org/en-US/docs/… and developer.mozilla.org/en-US/docs/Web/API/document.evaluate and post details of code used and errors you get in case the documentation does not help.