AntDomElement (AntDomElement from, final String id, final boolean skipCustomTags) { if (id.equals(from.getId().getRawText())) { return from; } final Ref<AntDomElement> result = new Ref<>(null); from.accept(new AntDomRecursiveVisitor() { @Override public void visitAntDomCustomElement(AntDomCustomElement custom) { if (!skipCustomTags) { super.visitAntDomCustomElement(custom); } } @Override public void visitAntDomElement(AntDomElement element) { if (result.get() != null) { return; } if (id.equals(element.getId().getRawText())) { result.set(element); return; } super.visitAntDomElement(element); } }); return result.get(); }