code: public void collectIds(List<String> ids) {
      ids.add(attribute("id"));
      for (Element child : elements) {
        child.collectIds(ids);
      }
    }
docs: allows to recursively collect the ids of all elements in the tree.