void (final XmlTag tag) { if (isSectioningContentElement(tag) || isSectioningRootElement(tag)) { if (myCurrentOutlinee != null) { myStack.push(myCurrentOutlinee); } myCurrentOutlinee = new SectionHolder(tag); myCurrentSection = new Section(tag); myCurrentOutlinee.addChildSection(myCurrentSection); } else if (myCurrentOutlinee == null) { // do nothing } else if (isHeader(tag)) { if (myCurrentSection.getHeader() == null) { myCurrentSection.setHeader(tag); } else if (myCurrentOutlinee.getChildren().getLast().getHeader() == null || compareHeaderRanks(tag, myCurrentOutlinee.getChildren().getLast().getHeader()) >= 0) { myCurrentSection = new Section(tag); myCurrentSection.setHeader(tag); myCurrentOutlinee.addChildSection(myCurrentSection); } else { Section candidateSection = myCurrentSection; do { if (compareHeaderRanks(tag, candidateSection.getHeader()) < 0) { myCurrentSection = new Section(tag); myCurrentSection.setHeader(tag); candidateSection.addChildSection(myCurrentSection); break; } candidateSection = candidateSection.getParent(); } while (true); } //myStack.push(); not needed, because our iterator doesn't enter hidden elements } }