Greetings.

I Have created two methods to facilitate the use of XPath Queries.

Functions

Node.prototype.queryPathAll = function (xmlns, expression) {
  let data = this.ownerDocument || this;
  let nodes = data.evaluate(
    expression,
    this,
    () => xmlns,
    XPathResult.ORDERED_NODE_ITERATOR_TYPE,
    null);
  let results = [];
  let node = nodes.iterateNext();
  while (node) {
    // Add the link to the array
    results.push(node);
    // Get the next node
    node = nodes.iterateNext();
  }
  return results;
};

Node.prototype.queryPath = function (xmlns, expression) {
  let data = this.ownerDocument || this;
  return data.evaluate(
    expression,
    this,
    () => xmlns,
    XPathResult.FIRST_ORDERED_NODE_TYPE,
    null)
    .singleNodeValue;
};

Usage

Set "xmlns" to "null" for OPML, RSS, HTML, and other documents without "xmlns".

let nodeFeed = xmlFile.queryPath(xmlns.atom, "atom:feed")
let nodeNext = nodeFeed.queryPath(xmlns.atom, "atom:link[@rel='next']");
let nodePrevious = nodeFeed.queryPath(xmlns.atom, "atom:link[@rel='previous']");

let nodesEntry = nodeFeed.queryPathAll(xmlns.atom, "atom:entry");
for (const nodeEntry of nodesEntry) {
  // Your code here.
}

Namespace

xmlns = {
  "atom"      : "http://www.w3.org/2005/Atom",
  "content"   : "http://purl.org/rss/1.0/modules/content/",
  "dc"        : "http://purl.org/dc/elements/1.1/",
  "foaf"      : "http://xmlns.com/foaf/0.1/",
  "geo"       : "http://www.w3.org/2003/01/geo/wgs84_pos#",
  "metalink4" : "urn:ietf:params:xml:ns:metalink",
  "metalink"  : "http://www.metalinker.org/",
  "owl"       : "http://www.w3.org/2002/07/owl#",
  "rdf"       : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
  "rdfs"      : "http://www.w3.org/2000/01/rdf-schema#",
  "rss"       : "http://purl.org/rss/1.0/",
  "smf"       : "http://www.simplemachines.org/xml/recent",
  "syn"       : "http://purl.org/rss/1.0/modules/syndication/",
  "xhtml"     : "http://www.w3.org/1999/xhtml",
  "xlink"     : "http://www.w3.org/1999/xlink",
  "xsl"       : "http://www.w3.org/1999/XSL/Transform"
}

For examples, please refer to the source code of Greasemonkey StremBurner (Newspaper).

https://openuserjs.org/scripts/sjehuda/Newspaper

Kindly,
Schimon

It be better to add dictionary support, so it be possible to query elements of different XML Namespace.

For instance, to query Atomsub of XMPP would require this XPath query "pubsub:item/atom:entry".