code: public static void process(final Node node, final boolean recurseToChildren, final NodeProcessor visitor) {
  
          // Process the current Node, if the NodeProcessor accepts it.
          if (visitor.accept(node)) {
              visitor.process(node);
          }
  
          NamedNodeMap attributes = node.getAttributes();
          for (int i = 0; i < attributes.getLength(); i++) {
              Node attribute = attributes.item(i);
  
              // Process the current attribute, if the NodeProcessor accepts it.
              if (visitor.accept(attribute)) {
                  visitor.process(attribute);
              }
          }
  
          if (recurseToChildren) {
              NodeList children = node.getChildNodes();
              for (int i = 0; i < children.getLength(); i++) {
                  Node child = children.item(i);
  
                  // Recurse to Element children.
                  if (child.getNodeType() == Node.ELEMENT_NODE) {
                      process(child, true, visitor);
                  }
              }
          }
      }
docs: Drives the supplied visitor to process the provided Node and all its children, should the recurseToChildren flag
  be set to <code>true</code>. All attributes of the current node are processed before recursing to children (i.e.
  breadth first recursion).
  
  @param node              The Node to process.
  @param recurseToChildren if <code>true</code>, processes all children of the supplied node recursively.
  @param visitor           The NodeProcessor instance which should process the nodes.