document.createNSResolver(nodeResolver) is a deprecated Document method from the XPath evaluator surface. Historically it built an XPathNSResolver from a node. Today it simply returns that same node so old scripts keep working.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call document.createNSResolver. Start with this line.
JavaScript
document.createNSResolver(nodeResolver)
Call
What it does
document.createNSResolver(nodeResolver)
Primary signature.
document.createNSResolver(...)
Call with the arguments your case needs.
Built into the browser. Call createNSResolver(...) on document — no import required.
Library declarations
JavaScript
document.createNSResolver(nodeResolver)
Parameters
Parameter
Description
nodeResolver
Required. A Node (returned as-is today)
Return Value
Return Value
Description
*
Same node reference
JavaScript Examples
Example 1 — Returns the Same Node (MDN)
Today the method is an identity helper for the argument you pass.
Call the method. Engines keep it for compatibility.
Compare with ===. MDN: return value is the input itself.
No wrapper. Do not expect a separate XPathNSResolver object today.
Example 2 — Legacy Pattern You May See
Recognize this shape in old tutorials — then migrate away from it.
JavaScript
// Legacy-looking sample (do not copy into new apps):
const contextNode = document.documentElement;
const resolver = document.createNSResolver(contextNode);
const result = document.evaluate(
"//*",
document,
resolver, // today this is just contextNode again
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null
);
console.log(result.snapshotLength);
console.log(resolver === contextNode); // true
Store the URI in a named constant (SVG namespace string).
Write a mapper that returns a URI for known prefixes, else null.
Pass the function as the third argument to evaluate.
XPath engine calls it for each prefix in the expression.
Compatibility
Browser Support
Document.createNSResolver() is Deprecated on MDN. Engines may still expose it as an identity helper for compatibility. Prefer resolver functions with evaluate / createExpression.
✓ Deprecated
Document.createNSResolver()
Legacy XPathNSResolver helper — MDN says it now returns the input as-is.
LegacyCompatibility only
Google ChromeSupported (deprecated)
Legacy
Microsoft EdgeSupported (deprecated)
Legacy
OperaSupported (deprecated)
Legacy
Apple SafariSupported (deprecated)
Legacy
Mozilla FirefoxSupported (deprecated)
Legacy
Internet ExplorerLegacy support
Legacy
createNSResolver()Avoid in new code
Bottom line: Recognize createNSResolver in old XPath samples. For new queries, pass a resolver function or null. See the MDN createNSResolver() reference.
Frequently Asked Questions
MDN: it used to create a custom XPathNSResolver. It now returns the input node as-is and is kept only for compatibility.
Yes. MDN marks Document.createNSResolver() as Deprecated. Avoid it in new projects.
MDN: it returns nodeResolver itself — the same Node you passed in.
Pass a namespace resolver function (prefix => namespaceURI or null) to document.evaluate() or document.createExpression(), or pass null when your XPath has no prefixes.
Older XPath APIs expected an XPathNSResolver object. createNSResolver(node) historically wrapped a node so prefix lookups could use that node’s namespace context.
No for new code. Prefer an explicit resolver function or null. Recognize createNSResolver only when reading legacy samples.