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

/**
 * Finds the attribute value with the given name
 * @param node the node/* w w  w .j  av a 2s.  co m*/
 * @param name the attribute name
 * @return the attribute value
 */
public static String findAttribute(Node node, String name) {
    Node attr = node.getAttributes().getNamedItem(name);
    return attr.getTextContent();
}

From source file:Main.java

public static void copyAttributes(Node from, Node to) {
    NamedNodeMap map = from.getAttributes();
    for (int i = 0; i < map.getLength(); i++) {
        Node attr = map.item(i);//www .j a va 2  s.c om
        addAttribute(to, attr.getNodeName(), attr.getNodeValue());
    }
}

From source file:Main.java

public static long getAttributeLongValue(Node n, String item, long dflt) {
    final Node d = n.getAttributes().getNamedItem(item);
    if (d == null)
        return dflt;
    final String val = d.getNodeValue();
    if (val == null)
        return dflt;
    return Long.parseLong(val);
}

From source file:Main.java

public static String getAttribute(Node node, String name) {
    NamedNodeMap attr = node.getAttributes();
    for (int n = 0; n < attr.getLength(); n++) {
        Node attribute = attr.item(n);
        if (attribute.getNodeName().equals(name))
            return attribute.getNodeValue();
    }/*from w w  w.  j  a v a 2s.  co m*/
    return "";
}

From source file:Main.java

public static void setAttributeValue(Node node, String attName, String attValue) {
    Node attr = node.getAttributes().getNamedItem(attName);
    attr.setNodeValue(attValue);/*from w  w w  .ja  v a  2  s .c om*/
}

From source file:Main.java

public static void removeNodeAttributes(Node node) {

    NamedNodeMap attrs = node.getAttributes();

    if ((attrs != null) && (attrs.getLength() > 0)) {
        String[] names = new String[attrs.getLength()];
        for (int i = 0; i < names.length; i++) {
            names[i] = attrs.item(i).getNodeName();
        }//from   ww w .j  a v a 2 s .c  om
        for (int i = 0; i < names.length; i++) {
            attrs.removeNamedItem(names[i]);
        }
    }

}

From source file:Main.java

public static String getAttribute(Node node, String attributeName) {
    Node attribute = node.getAttributes().getNamedItem(attributeName);
    if (attribute != null) {
        return attribute.getNodeValue();
    }/*from  w w  w . ja  va 2s  . c om*/
    return null;
}

From source file:Main.java

public static Node getAttributeNode(Node sNode, String attribName) {
    NamedNodeMap attrs = sNode.getAttributes();
    if (attrs != null) {
        return attrs.getNamedItem(attribName);
    }/*from w ww  .ja  v  a  2  s  .  c om*/
    return null;
}

From source file:Main.java

public static String getSeriesIDforLine(Node linenode) {
    try {//from w  ww. ja  v  a  2 s .c  o m
        String lineid = linenode.getAttributes().getNamedItem("id").getFirstChild().getNodeValue();
        return lineid;
    } catch (Exception eee) {
        return null;
    }
}

From source file:Main.java

public static String getAttribute(Node n, String s) {
    return n.getAttributes().getNamedItem(s).getTextContent();
}