public static Stream<Node> streamChildNodes(@Nullable Node node) { if (node == null) { return Stream.empty(); } NodeList childNodes = node.getChildNodes(); return SdcctIteratorUtils.stream(new NodeListIterator(childNodes), childNodes.getLength()); }
public static List<String> extractTextContent(List<String> textContent, Node node) { CrigttIteratorUtils.stream(new NodeListIterator(node)).forEach(childNode -> { if (childNode instanceof Text) { textContent.add(childNode.getNodeValue()); } else if (childNode instanceof Element) { extractTextContent(textContent, childNode); } }); return textContent; }
/** * Gets an {@link Iterator} that wraps the specified {@link NodeList}. * The returned {@link Iterator} can be used for a single iteration. * * @param nodeList the node list to use, may not be null * @return a new, single use {@link Iterator} * @throws NullPointerException if nodeList is null * @since 4.0 */ public static NodeListIterator nodeListIterator(final NodeList nodeList) { if (nodeList == null) { throw new NullPointerException("NodeList must not be null"); } return new NodeListIterator(nodeList); }
/** * Gets an {@link Iterator} that wraps the specified node's childNodes. * The returned {@link Iterator} can be used for a single iteration. * <p> * Convenience method, allows easy iteration over NodeLists: * <pre> * Iterator<Node> iterator = IteratorUtils.nodeListIterator(node); * for(Node childNode : IteratorUtils.asIterable(iterator)) { * ... * } * </pre> * * @param node the node to use, may not be null * @return a new, single use {@link Iterator} * @throws NullPointerException if node is null * @since 4.0 */ public static NodeListIterator nodeListIterator(final Node node) { if (node == null) { throw new NullPointerException("Node must not be null"); } return new NodeListIterator(node); }