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