List of utility methods to do XML NodeList
void | removeNodeListContent(NodeList nodeList) remove Node List Content while (nodeList.getLength() > 0) {
removeNode(nodeList.item(0));
|
Node | replace(Node src, NodeList nodes) replace Document doc = src.getOwnerDocument(); Node parent = src.getParentNode(); ArrayList<Node> copy = new ArrayList<Node>(); for (int i = 0; i < nodes.getLength(); i++) copy.add(nodes.item(i)); Node sibling = src.getNextSibling(); parent.removeChild(src); Node last = sibling; ... |
void | replaceElement(Element oldElement, NodeList newNodes) replace Element Document doc = oldElement.getOwnerDocument(); Node parent = oldElement.getParentNode(); int len = newNodes.getLength(); for (int i = 0; i < len; i++) { Node n = newNodes.item(i); if (!doc.equals(n.getOwnerDocument())) { n = doc.importNode(n, true); parent.insertBefore(n, oldElement); parent.removeChild(oldElement); |
void | replaceElement(Element oldElement, NodeList newNodes) replace Element Document doc = oldElement.getOwnerDocument(); Node parent = oldElement.getParentNode(); int len = newNodes.getLength(); for (int i = 0; i < len; i++) { Node n = newNodes.item(i); if (!doc.equals(n.getOwnerDocument())) { n = doc.importNode(n, true); parent.insertBefore(n, oldElement); parent.removeChild(oldElement); |
Node | searchDialogByName(NodeList nodeList, String id) search Dialog By Name for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); String idd = getNodeAttributeValue(node, "id"); if (id.equals(idd)) return node; return null; |
Element | selectElement(NodeList nodeList, String name) Returns the first element in the spacified node list that has a local name equal to the spacified name. Element element = null; for (int i = 0; i < nodeList.getLength() && element == null; i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && node.getLocalName().equals(name)) element = (Element) node; return element; |
int | size(final NodeList nodeList) Retrieves the number of Nodes in the NodeList return nodeList == null ? 0 : nodeList.getLength();
|
List | sort(NodeList classesNodeList) sort List<Element> nodes = new ArrayList<Element>(); for (int i = 0; i < classesNodeList.getLength(); i++) { nodes.add((Element) classesNodeList.item(i)); Collections.sort(nodes, new Comparator<Element>() { public int compare(Element o1, Element o2) { return o1.getAttribute("qualifiedName").compareTo(o2.getAttribute("qualifiedName")); }); return nodes; |
Stream | stream(NodeList list) stream return IntStream.range(0, list.getLength()).mapToObj(list::item);
|
Stream | stream(NodeList nodeList) stream Node[] nodes = new Node[nodeList.getLength()]; for (int i = 0; i < nodeList.getLength(); i++) { nodes[i] = nodeList.item(i); return Stream.of(nodes); |