code: public List<Element> findElements(Class<?> type) {
      List<Element> result = new ArrayList<>();
      LinkedList<Element> stack = new LinkedList<>(this.getChildren());
  
      if (this.getClass() == type) {
        result.add(this);
      }
  
      while (!stack.isEmpty()) {
        Element child = stack.pop();
        stack.addAll(0, child.getChildren());
        if (child.getClass() == type) {
          result.add(child);
        }
      }
  
      return result;
    }
docs: Search the MessageML tree (depth-first) for elements of a given type.
  @param type the class of elements to find
  @return found elements