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

StringmergeTextContent(NodeList nodes)
based on the following quote from public Java5 javadoc of org.w3c.dom.Node.getTextContent method: "concatenation of the textContent attribute value of every child node, excluding COMMENT_NODE and PROCESSING_INSTRUCTION_NODE nodes.
StringBuffer buf = new StringBuffer();
for (int i = 0; i < nodes.getLength(); i++) {
    Node n = nodes.item(i);
    final String text;
    switch (n.getNodeType()) {
    case Node.COMMENT_NODE:
    case Node.PROCESSING_INSTRUCTION_NODE:
        text = null;
...
ObjectparserXml(NodeList employees, Class class_type)
parser Xml
Map map = class_type.newInstance();
String value = null;
for (int i = 0; i < employees.getLength(); i++) {
    Node employee = employees.item(i);
    if (employee.getNodeType() != 8)
        if (employee.getNodeType() == 1 || employee.getNodeValue() == null
                || employee.getNodeValue().trim().isEmpty()) {
            if (employee.hasChildNodes() || employee.hasAttributes()) {
...
MapparseSwitcherConfigs(NodeList switcherConfigNodes)
parse Switcher Configs
Map<String, String> configs = new HashMap<>();
for (int i = 0; i < switcherConfigNodes.getLength(); ++i) {
    NamedNodeMap attributes = switcherConfigNodes.item(i).getAttributes();
    if (attributes != null) {
        String[] keyValue = parseConfigAttr(attributes);
        configs.put(keyValue[0], keyValue[1]);
return configs;
Map>parseSwitchers(NodeList switcherNodes)
parse Switchers
Map<String, Map<String, String>> switchers = new HashMap<>();
for (int i = 0; i < switcherNodes.getLength(); ++i) {
    Node switcherNode = switcherNodes.item(i);
    NamedNodeMap switcherAttributes = switcherNode.getAttributes();
    if (switcherAttributes != null) {
        String switcherClassName = switcherAttributes.getNamedItem("class").getTextContent();
        Map<String, String> configs = parseSwitcherConfigs(switcherNode.getChildNodes());
        switchers.put(switcherClassName, configs);
...
MapparseWidget(NodeList widgetList)
parse Widget
Map map = new HashMap();
try {
    for (int i = 0; i < widgetList.getLength(); i++) {
        Node widget = widgetList.item(i);
        if (widget.getNodeName().equals("widget")) {
            String id = widget.getAttributes().getNamedItem("id").getTextContent();
            Map attrMap = parseAttribute(widget.getChildNodes());
            map.put(id, attrMap);
...
voidprettyPrintLoop(NodeList nodes, StringBuilder string, String indentation)
pretty Print Loop
for (int index = 0; index < nodes.getLength(); index++) {
    prettyPrintLoop(nodes.item(index), string, indentation);
voidprintNode(NodeList nodeList, int level)
print Node
level++;
if (nodeList != null && nodeList.getLength() > 0) {
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            System.out.println(node.getNodeName() + "[" + level + "]");
            printNode(node.getChildNodes(), level);
            if (level > depthOfXML)
...
voidprintNodeList(NodeList nodes)
print Node List
for (int i = 0; i < nodes.getLength(); i++) {
    System.out.println(nodes.item(i).getNodeValue());
voidprintNodeTypes(NodeList rows)
For testing purpose, it print out Node list
System.out.println("\tenumerating NodeList (of Elements):");
System.out.println("\tClass\tNT\tNV");
for (int ri = 0; ri < rows.getLength(); ri++) {
    Node n = (Node) rows.item(ri);
    if (n instanceof Element) {
        System.out.print("\tElement");
    } else
        System.out.print("\tNode");
...
voidremoveBlankTextNode(NodeList nodes)
remove Blank Text Node
for (int i = 0; i < nodes.getLength(); i++) {
    Node node = nodes.item(i);
    if (Node.TEXT_NODE == node.getNodeType() && 0 == node.getNodeValue().trim().length()) {
        removeNode(node);
for (int i = 0; i < nodes.getLength(); i++) {
    Node node = nodes.item(i);
...