/** * Returns the merged content of all children text nodes, if this node has no element children. * <p> * This will work when this node has only text and comment children.<br> * If it has element children, the default value is returned. * * @param def The default value. * @return The merged content of children texts (ignoring comments) or {@code def}. */ public String getText(String def) { if (children == null || children.isEmpty()) { return def; } else if (!hasChildren(Element.class)) { // Ignore comments final Iterable<Text> texts = getChildren(Text.class); if (Iterables.isEmpty(texts)) { return def; } else { final StringBuilder sb = new StringBuilder(); for (final Text text : texts) { sb.append(text.getContent()); } return sb.toString(); } } else { return def; } }
@Override public Element clone(boolean recurse) { final Element result = new Element(this); if (recurse) { for (final Child child : getChildren()) { result.addChild(child.clone(true)); } } return result; }
for (final Child child : element.getChildren()) { write(writer, child);