Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /**
     * @param n Node to examine
     * @param attr Attribute to look for
     * @param def Default value to return if attribute is not present
     * @return if the Node contains the named Attribute, the value, if not, the def parameter
     */
    public static String getAttributeIgnoreCase(Node n, String attr, String def) {
        NamedNodeMap attrs = n.getAttributes();
        if (attrs == null)
            return def;
        for (int i = 0; i < attrs.getLength(); i++) {
            Node ret = attrs.item(i);
            if (ret.getNodeName().equalsIgnoreCase(attr))
                return ret.getNodeValue();
        }
        return def;
    }
}