searchNode(paths, pos) {
    if (pos >= paths.length) {
      return this;
    }

    const component = paths[pos];
    if (component.name.startsWith("#") && pos < paths.length - 1) {
      // If it starts with a # then it's a class which is not a concept for
      // datasets elements (https://www.pdfa.org/norm-refs/XFA-3_3.pdf#page=96).
      return this.searchNode(paths, pos + 1);
    }
    const stack = [];
    let node = this;

    while (true) {
      if (component.name === node.nodeName) {
        if (component.pos === 0) {
          const res = node.searchNode(paths, pos + 1);
          if (res !== null) {
            return res;
          }
        } else if (stack.length === 0) {
          return null;
        } else {
          const [parent] = stack.pop();
          let siblingPos = 0;
          for (const child of parent.childNodes) {
            if (component.name === child.nodeName) {
              if (siblingPos === component.pos) {
                return child.searchNode(paths, pos + 1);
              }
              siblingPos++;
            }
          }
          // We didn't find the correct sibling
          // so just return the first found node
          return node.searchNode(paths, pos + 1);
        }
      }

      if (node.childNodes?.length > 0) {
        stack.push([node, 0]);
        node = node.childNodes[0];
      } else if (stack.length === 0) {
        return null;
      } else {
        while (stack.length !== 0) {
          const [parent, currentPos] = stack.pop();
          const newPos = currentPos + 1;
          if (newPos < parent.childNodes.length) {
            stack.push([parent, newPos]);
            node = parent.childNodes[newPos];
            break;
          }
        }
        if (stack.length === 0) {
          return null;
        }
      }
    }
  }
Search a node in the tree with the given path
foo.bar[nnn], i.e. find the nnn-th node named
bar under a node named foo.

@param {Array} paths - an array of objects as
returned by {parseXFAPath}.
@param {number} pos - the current position in
the paths array.
@returns {SimpleDOMNode} The node corresponding
to the path or null if not found.