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

/**
 * Getter for the attribute value of an attribute of the given name
 * for the specified node. The attribute value is returned as a string.
 * @param node Node./*from   w ww .  ja  va 2s . c  o  m*/
 * @param name Name of the attribute.
 * @return Returns the attribute value as string or null if the attribute
 * does not exist.
 */
static public String getAttrValString(Node node, String name) {
    NamedNodeMap attr = node.getAttributes();
    if (attr != null) {
        node = attr.getNamedItem(name);
        if (node != null)
            return (node.getNodeValue());
    }
    return (null);
}

From source file:Main.java

public static String getStartDateFromLineNode(Node linenode) {
    String date = "";
    Node t1 = linenode.getAttributes().getNamedItem("startdate");
    if (t1 != null)
        date = t1.getNodeValue();/*  w ww  . ja va2s  .  co m*/
    else
        date = linenode.getOwnerDocument().getElementsByTagName("startdate").item(0).getFirstChild()
                .getNodeValue();
    return date;
}

From source file:Main.java

public static boolean getAttributeBooleanValue(Node n, String item, boolean dflt) {
    final Node d = n.getAttributes().getNamedItem(item);
    if (d == null) {
        return dflt;
    }//from ww  w.  j a v a 2  s  .c o m
    final String val = d.getNodeValue();
    if (val == null) {
        return dflt;
    }
    return Boolean.parseBoolean(val);
}

From source file:Main.java

public static double getDouble(Node aNode, String attr, double defaultValue) {
    if (aNode.getAttributes().getNamedItem(attr) != null) {
        String attrString = aNode.getAttributes().getNamedItem(attr).getNodeValue();
        double year = Double.parseDouble(attrString);
        return year;
    } else {//from   ww  w.ja  va  2 s  . c  om
        return defaultValue;
    }
}

From source file:Main.java

public static List<Node> getAttributes(Node node) {
    NamedNodeMap attrs = node.getAttributes();
    int attrCount = attrs.getLength();
    List<Node> nodes = new ArrayList<Node>(attrCount);
    for (int i = 0; i < attrCount; i++) {
        nodes.add(attrs.item(i));//  w  ww .j  a va2s.c o  m
    }
    return nodes;
}

From source file:Main.java

/**
 * Get an attribute./*from ww  w .  j  av  a  2  s.c om*/
 * 
 * @param node node
 * @param attr attribute name
 * @return value
 */
public static String getAttr(Node node, String attr) {
    Node attrNode = node.getAttributes().getNamedItem(attr);
    return attrNode != null ? attrNode.getNodeValue() : "";
}

From source file:Main.java

/**
 * Get an attribute./* w  ww  . j  av a 2 s .c om*/
 * 
 * @param node node
 * @param attr attribute name
 * @return value or null
 */
public static String getAttrOrNull(Node node, String attr) {
    Node attrNode = node.getAttributes().getNamedItem(attr);
    return attrNode != null ? attrNode.getNodeValue() : null;
}

From source file:Main.java

public static void incrementAttributeValue(Node node, String attName, int value) {
    Node attr = node.getAttributes().getNamedItem(attName);
    String attValue = String.valueOf(Integer.parseInt(attr.getNodeValue()) + value);
    attr.setNodeValue(attValue);//from   ww  w.j  av  a  2s  .com
}

From source file:Main.java

public static String getAttribute(Node node, String name) {
    NamedNodeMap namedNodeMap = node.getAttributes();
    if (namedNodeMap == null) {
        return null;
    }// ww w .ja v  a 2s .com
    Node attrNode = namedNodeMap.getNamedItem(name);
    if (attrNode == null) {
        return null;
    }
    return attrNode.getNodeValue();
}

From source file:Main.java

public static String getAttribute(Node node, String attrName) {
    NamedNodeMap attr = node.getAttributes();
    if (attr != null) {
        Node nodeAttr = attr.getNamedItem(attrName);
        if (nodeAttr != null) {
            return nodeAttr.getNodeValue();
        }//from  ww  w. j  a v  a2 s.c o m
    }
    return null;
}