Java XML Element Child Append appendNode(Node node, StringBuilder sb, int indent)

Here you can find the source of appendNode(Node node, StringBuilder sb, int indent)

Description

append Node

License

Apache License

Parameter

Parameter Description
licenseElement a parameter
sb a parameter

Declaration

private static void appendNode(Node node, StringBuilder sb, int indent) 

Method Source Code

//package com.java2s;
/**//from  ww  w .  j  ava 2 s  .  c  om
 * Copyright (c) 2016 Source Auditor Inc.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
*/

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    private static final String INDENT_STRING = "   ";

    /**
     * @param licenseElement
     * @param sb
     */
    private static void appendNode(Node node, StringBuilder sb, int indent) {
        for (int i = 0; i < indent; i++) {
            sb.append(INDENT_STRING);
        }
        sb.append("Node Type: ");
        sb.append(node.getNodeType());
        sb.append(", Node Name: ");
        sb.append(node.getNodeName());
        sb.append(", Node Value: '");
        sb.append(node.getNodeValue());
        sb.append('\'');
        sb.append(", Node Text: '");
        sb.append(node.getTextContent());
        sb.append("'\n");
        if (node.hasChildNodes()) {
            NodeList children = node.getChildNodes();
            for (int i = 0; i < children.getLength(); i++) {
                appendNode(children.item(i), sb, indent + 1);
            }
        }
    }
}

Related

  1. appendNewElement(Document document, Element parent, Enum el)
  2. appendNewElement(Document document, Element parent, String element, Object content, String namespace)
  3. appendNewElement(Node parent, String elementName)
  4. appendNewElementIfNotNull(Document document, Element parent, Enum el, Object content, String namespace)
  5. appendNewElementIfNotNull(Document document, Element parent, Enum el, Object content, String namespace)