Example usage for org.w3c.dom Node getAttributes

List of usage examples for org.w3c.dom Node getAttributes

Introduction

In this page you can find the example usage for org.w3c.dom Node getAttributes.

Prototype

public NamedNodeMap getAttributes();

Source Link

Document

A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.

Usage

From source file:Main.java

/**
 * Returns an attribute of the specified tag with the name provided.
 *
 * @param node/*from  www.j a v a 2s .c  o m*/
 * @param name
 * @return The attribute if its defined, or null.
 */
public static String getAttribute(Node node, String name, String defVal) {
    Node att = node.getAttributes().getNamedItem(name);
    return att == null ? defVal : att.getNodeValue();
}

From source file:Main.java

/**
 * @param sampleNode/*w ww. j a  v  a2s. co  m*/
 * @return The time and time unit from a sample. e.g. "day 1" or "week 2".
 *         Returns "" if no time information is avalilable.
 */
public static String getSampleTimeUnit(Node sampleNode) {
    String timeunit;
    if (sampleNode.getAttributes() == null || sampleNode.getAttributes().getNamedItem("unit") == null)
        timeunit = null;
    else
        timeunit = sampleNode.getAttributes().getNamedItem("unit").getFirstChild().getNodeValue();

    return timeunit;
}

From source file:Main.java

public static String getAttributeValue(Node node, String attribute) {
    Node att = node.getAttributes().getNamedItem(attribute);

    if (att == null)
        return null;

    return att.getTextContent();
}

From source file:Main.java

public static Double getAttributeValueAsDouble(Node node, String attributeName) {
    return Double.parseDouble(node.getAttributes().getNamedItem(attributeName).getTextContent());
}

From source file:Main.java

public static String getAttributeValue(Node node, String attributeName) {
    Node n = node.getAttributes().getNamedItem(attributeName);
    return (n == null) ? null : n.getNodeValue();
}

From source file:Main.java

/**
 * @param n Node to examine/*w  ww . j  av a2s. c  om*/
 * @param attr Attribute to look for
 * @return true if the Node contains the named Attribute
 */
public static boolean hasAttribute(Node n, String attr) {
    NamedNodeMap attrs = n.getAttributes();
    if (attrs == null)
        return false;
    Node ret = attrs.getNamedItem(attr);
    if (ret == null)
        return false;
    else
        return true;
}

From source file:Main.java

public static String getNodeAttribute(Node n, String attrName) {
    Node namedAttr = n.getAttributes().getNamedItem(attrName);
    if (namedAttr != null)
        return namedAttr.getNodeValue();
    else/*  w  ww  . ja  v  a 2 s.  c  o m*/
        return null;
}

From source file:Main.java

/**
 * Method getAttr./*from w w  w .  ja v a 2 s . co  m*/
 * <br>Returns the Attribute with the given attrName at node
 * <br>Example<br>
 * This example returns the 'state' attribute from the address node:
 *      Attr state = getAttr(address,"state")
 * @param node - Node to search
 * @param attrName - Name of the attribute to find
 * @return Attr - Attribute found
 */
public static Attr getAttr(Node node, String attrName) {
    NamedNodeMap attrs = node.getAttributes();
    return (Attr) attrs.getNamedItem(attrName);
}

From source file:Main.java

public static final String getAtrributeValueOf(Node node, String attribute) {
    Node _node = node.getAttributes().getNamedItem(attribute);
    return getValueOf(_node);
}

From source file:Main.java

public static void dumpNodeDetails(Node node) throws Exception {
    NamedNodeMap attributes = node.getAttributes();
    for (int t = 0; t < attributes.getLength(); t++) {
        Node aNode = attributes.item(t);
        log.info("aName = " + aNode.getNodeName() + " : aValue = " + aNode.getNodeValue());
    }/*from ww  w  .jav a 2s. c  om*/
}