Java Utililty Methods XML NodeList

List of utility methods to do XML NodeList

Description

The list of methods to do XML NodeList are organized into topic(s).

Method

voidremoveNodeListContent(NodeList nodeList)
remove Node List Content
while (nodeList.getLength() > 0) {
    removeNode(nodeList.item(0));
Nodereplace(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;
...
voidreplaceElement(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);
voidreplaceElement(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);
NodesearchDialogByName(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;
ElementselectElement(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;
intsize(final NodeList nodeList)
Retrieves the number of Nodes in the NodeList
return nodeList == null ? 0 : nodeList.getLength();
Listsort(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;
Streamstream(NodeList list)
stream
return IntStream.range(0, list.getLength()).mapToObj(list::item);
Streamstream(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);