javascript - XPath query against DocumentFragment -


i need dom surgery on documentfragment, , i'm trying use xpath find nodes need modified. however, can't figure out how document.evaluate work on fragment. tried

fragment.ownerdocument.evaluate(     '//*',     fragment.ownerdocument,     null,     xpathresult.any_type,     null ) 

but did not work.

use svg temp element if need run xpath against xml, since security restrictions prevent evaluating xpath expressions on element not attached dom:

<!doctype html> <html lang="en"> <head> <title>xpath context</title> <meta charset="utf-8"> </head> <body>  <svg id="model" version="1.1" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 100"">   <?foo bar?> </svg>  <script type="text/javascript;version=1.7"> function $xpath(axpath, acontext)   {     let nodes = [];     acontext = document.getelementbyid("model") || doc;     let results = document.evaluate(axpath, acontext, null, xpathresult.any_type, null);     let node;      while ((node = results.iteratenext())) {       nodes.push(node);     }      return nodes;   } </script> </body> </html> 

or use javascript implementation.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -