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 {
    private static final String RESOURCE_ITEM = "item";
    private static final String ATTRIBUTE_TYPE = "type";

    public static String getResourceAttributeValue(Node node, String resourceType, String attribute) {
        String currentNodeName = node.getNodeName();
        if (currentNodeName.startsWith(resourceType)) {
            return getAttributeValue(node, attribute);
        } else if (currentNodeName.startsWith(RESOURCE_ITEM)) {
            String typeValue = getAttributeValue(node, ATTRIBUTE_TYPE);
            if (resourceType.equals(typeValue)) {
                return getAttributeValue(node, attribute);
            }
        }
        return null;
    }

    public static String getAttributeValue(Node node, String attribute) {
        NamedNodeMap attributes = node.getAttributes();
        if (attributes != null) {
            Node nameAttr = attributes.getNamedItem(attribute);
            if (nameAttr != null) {
                return nameAttr.getNodeValue();
            }
        }
        return null;
    }
}