Java Utililty Methods XML Node Tree

List of utility methods to do XML Node Tree

Description

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

Method

voiddump(final Node node)
Recursively walks the DOM tree starting at the given Node printing the gory details of its construction to System.out.
doDump(System.out, node, 0);
voiddump(Node node)
dump
System.out.println("Node: " + node.getNodeName());
NamedNodeMap nnm = node.getAttributes();
if (nnm != null) {
    for (int i = 0; i < nnm.getLength(); i++) {
        Node n = nnm.item(i);
        System.out.println("   " + n.getNodeName() + ":" + n.getNodeValue());
StringdumpTree(Node node)
dump Tree
StringBuilder sb = new StringBuilder();
Stack<Node> stack = new Stack<Node>();
int level = 0;
while (node != null || !stack.isEmpty()) {
    if (node == null) {
        do {
            node = stack.pop();
            --level;
...
NodemoveSubTree(Node from, Node to, Node context)
Copies all child nodes from the first Element tree into the second Element tree inserted before the given context node.
NodeList children = from.getChildNodes();
Node[] asArray = convertToArray(children);
Document fromDoc = from.getOwnerDocument();
Document toDoc = to.getOwnerDocument();
for (int n = 0; n < asArray.length; ++n) {
    from.removeChild(asArray[n]);
    if (fromDoc != toDoc)
        asArray[n] = toDoc.importNode(asArray[n], true);
...