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 {

    public static String getAttribute(Node pNode, String attrName) {
        try {
            NamedNodeMap name = pNode.getAttributes();
            if (name.getLength() > 0) {
                Node node = name.getNamedItem(attrName);
                if (node != null) {
                    String attributeValue = name.getNamedItem(attrName).getNodeValue();
                    return attributeValue;
                } else {
                    return null;
                }
            } else {
                return null;
            }
        } catch (Exception e) {
            return null;
        }

    }
}