@Override protected List<Item> transform(List<Item> items) { Tag enclosure = null; List<String> children = null; List<Tag> enclosureChildTags = null; for (Item i : items) { if (i instanceof Tag) { Tag tag = (Tag) i; if (isEnclosure(tag)) { if (tag.getType() == Tag.Type.OPEN) { // found opening enclosure enclosure = tag; children = getChildren(enclosure); enclosureChildTags = new ArrayList<Tag>(); } else if (tag.getType() == Tag.Type.CLOSE) { // tidy up on close tag updateEnclosureChildId(enclosure, children, enclosureChildTags); enclosure = null; children = null; enclosureChildTags = null; } } else if (enclosure != null && !children.isEmpty()) { // if we have open enclosure tag and children to find int index = checkIfTagIsChild(tag, children, enclosureChildTags); if (index != -1) { onChildFound(tag, children, enclosureChildTags, index); } } } } return items; }