I need to do some DOM surgery on a DocumentFragment
, and I'm trying to use XPath to find the nodes that need to be modified. However, I can't figure out how to get document.evaluate
to work on a fragment. I tried
fragment.ownerDocument.evaluate(
'//*',
fragment.ownerDocument,
null,
XPathResult.ANY_TYPE,
null
)
but that did not work.
Use an
svg
as a temp element if you need to run XPath against XML, since security restrictions prevent evaluating XPath expressions on an element not attached to the DOM:Or use a JavaScript implementation.