Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    /**
     * Extract the text content of a named node from a list of nodes.
     * Returns null if the node is not found.
     *
     * @param map attribute node map
     * @param attrName name of the attribute to extract from the list
     * @return found node text or null if not found
     */
    public static String getAttributeTextFromList(final NamedNodeMap map, final String attrName) {

        String text = null;

        if (map != null) {
            final Node node = getAttributeFromList(map, attrName);

            if (node != null) {
                text = node.getTextContent();
            }
        }

        return text;
    }

    /**
     * Extract a named attribute from a node map.
     *
     * @param map attribute node map
     * @param attrName name of the attribute to extract from the list
     * @return found node or null if not found
     */
    public static Node getAttributeFromList(final NamedNodeMap map, final String attrName) {

        Node node = null;

        if (map != null) {
            for (int i = 0; i < map.getLength(); i++) {
                if (attrName.equalsIgnoreCase(map.item(i).getNodeName())) {
                    node = map.item(i);
                }
            }
        }

        return node;
    }
}