Example usage for org.w3c.dom Element getAttribute

List of usage examples for org.w3c.dom Element getAttribute

Introduction

In this page you can find the example usage for org.w3c.dom Element getAttribute.

Prototype

public String getAttribute(String name);

Source Link

Document

Retrieves an attribute value by name.

Usage

From source file:Main.java

public static Map<String, Element> mapFromArrayListByAttribute(ArrayList<Element> list, String attribName) {
    Map<String, Element> map = new HashMap<String, Element>();
    for (Element e : list) {
        map.put(e.getAttribute(attribName), e);
    }//from   w w  w .j  a  v  a 2s . com
    return map;
}

From source file:Main.java

public static Boolean parseBoolean(Element element, String key) {
    String value = element.getAttribute(key);
    if (value != null && !value.isEmpty()) {
        if ("1".equals(value) || "true".equals(value)) {
            return true;
        } else {/* w  ww  . j a  va  2  s  . c  o m*/
            return false;
        }
    }
    return null;
}

From source file:Main.java

public static Date getXMLDate(Element e, String attrName) {
    String s = e.getAttribute(attrName);
    if (s == null || s.length() == 0)
        return null;
    try {/*w  w  w.j ava 2s. c  o  m*/
        return parseDate(s);
    } catch (Exception exc) {
        return null;
    }
}

From source file:Main.java

/**
 * @param eElement element containing boolean attribute
 * @param atribute name of attribute in element
 * @return value of boolean or null if attribute not exists
 *///from  ww w . j av  a 2 s.  c  o  m
public static Boolean getBooleanElementAtribute(Element eElement, String atribute) {
    String atr = eElement.getAttribute(atribute);
    if (atr != null && !atr.isEmpty()) {
        return Boolean.valueOf(atr);
    }
    return null;
}

From source file:Main.java

private static String getPluginXmlId(Document doc) {
    Element element = doc.getDocumentElement();
    return element.getAttribute(ATTRIBUTE_ID);
}

From source file:Main.java

public static boolean getBooleanAttr(Element element, String name) {
    String attr = element.getAttribute(name);
    boolean ret = attr.equalsIgnoreCase("true");
    return ret;//from  ww  w  . j a  v a2s  .co  m
}

From source file:Main.java

/**
 * Returns the value of an attribute in the first element in a document with a given tag name.
 * This is useful for well structured documents when it is known that there is only
 * one such element and that it is has that attribute.
 * //from  w  w  w  . java2  s. c  o m
 * @param document The document to search within.
 * @param tagname The name of the element to access.
 * @param attributename The attribute's name.
 * @return The value of the attribute of the first respective element, or the empty string, if
 * the element of the attribute could not be found.
 */
public static String getAttribute(Document document, String tagname, String attributename) {
    NodeList list = document.getElementsByTagName(tagname);
    if (list.getLength() < 1) {
        return "";
    }
    Element tag = (Element) list.item(0);
    return tag.getAttribute(attributename);
}

From source file:Main.java

/**
 * Loads an optional integer attribute from a XML element
 *//*ww  w  .  j a  va 2 s  .  co m*/
public static int getIntAttribute(Element element, String name) {
    String value = element.getAttribute(name);

    if (value == null)
        return 0;

    if (value.length() == 0)
        return 0;

    return Integer.parseInt(value);
}

From source file:Main.java

public static String readStringAttr(Element element, String attributeName) {
    return element.getAttribute(attributeName);
}

From source file:Main.java

/**
 * Get an Attribute from an Element.  Returns an empty String if none found
 * http://www.java2s.com/Code/Java/XML/ReturnalistofnamedElementswithaspecificattributevalue.htm
 * @param element the containing Element.
 * @param name the attribute name./*from  w w w.  jav  a  2 s .  c o m*/
 * @return Attribute as a String.
 */
public static String getAttribute(Element element, String name) {
    return element.getAttribute(name);
}