/** * Adds all children of an array to this parent. * * @param children The children. */ public default void addChildren(Child... children) { for (final Child child : children) { addChild(child); } }
/** * Adds all children of an Iterable to this parent. * * @param children The children. */ public default void addChildren(Iterable<? extends Child> children) { for (final Child child : children) { addChild(child); } }
/** * Creates and adds a child element as last child, if possible. * * @param name The child name. * @return the created element. * @throws IllegalStateException If {@code child}'s parent can not be set. */ public default Element addElement(String name) { final Element child = new Element(name); return addChild(child); }
@Override public void comment(char[] ch, int start, int length) throws SAXException { LOGGER.trace("comment()"); if (top() == Action.KEEP) { // IGNORE_COMMENTS already handled in parser configuration checkActiveText(false); final Comment comment = new Comment(new String(ch, start, length)); currentParent.addChild(comment); resetActiveText(); } }
@Override public void characters(char[] ch, int start, int length) throws SAXException { LOGGER.trace("characters()"); if (top() == Action.KEEP) { if (activeText == null) { activeText = new Text(); currentParent.addChild(activeText); } activeText.appendContent(ch, start, length); } }
/** * Adds a comment as last child. * * @param content The comment content. * @param merge If {@code true}, then if last child exists and is a comment, * {@code content} is added to this last child.<br> * Otherwise, a comment child is created and added to last position. * @return The modified or created comment. */ public default Comment addComment(String content, boolean merge) { if (merge) { final Child last = getLastChild(); if (last != null && last.getType() == NodeType.COMMENT) { ((Comment) last).appendContent(content); return (Comment) last; } } final Comment result = new Comment(content); addChild(result); return result; }
currentParent.addChild(element); currentParent = element; resetActiveText();