List of usage examples for org.w3c.dom Element getAttribute
public String getAttribute(String name);
From source file:Main.java
/** * Loads an optional datetime attribute from a XML element *//*from w w w.j av a2 s. c o m*/ public static DateTime getDateAttribute(Element element, String name) { String value = element.getAttribute(name); if (value == null) return null; if (value.length() == 0) return null; DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd"); return dtf.parseDateTime(value); }
From source file:Main.java
public static String getAttribute(Element elem, String name, String def) { return elem.hasAttribute(name) ? elem.getAttribute(name) : def; }
From source file:Main.java
public static String getAttributeValue(Element current, String attrName) { return current.hasAttribute(attrName) ? current.getAttribute(attrName) : null; }
From source file:Main.java
private static String name(Element elem) { String name = elem.getAttribute("name"); if (!name.isEmpty()) { return elem.getTagName() + "[" + name + "]"; } else {/* w ww . j a v a 2 s . com*/ return elem.getTagName(); } }
From source file:Main.java
public static String getAttribute(Element element, String name) { String value = element.getAttribute(name); return replace(value); }
From source file:Main.java
public static String getAttribute(Element element, String name) { String value = element.getAttribute(name); if (value != null && !value.isEmpty()) { return value; }// ww w. ja v a 2s . c o m throw new NoSuchElementException(String.format("Element <%s> has no \"%s\" attribute", element, name)); }
From source file:Main.java
public static List<Element> filter(NodeList nl, String attr, String value) { List<Element> result = new ArrayList<Element>(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i);// ww w . j a v a2 s.co m if (!(n instanceof Element)) { continue; } Element e = (Element) n; if (!value.equals(e.getAttribute(attr))) { continue; } result.add(e); } return result; }
From source file:Main.java
/** * Return the value of an attribute on an element. * <p/>//from w ww. j a va2 s .c o m * The DOM getAttribute method returns an empty string if the attribute * doesn't exist. Here, we detect this and return null. */ public static String getAttribute(Element e, String name) { String value = e.getAttribute(name); if (value != null && value.length() == 0) { value = null; } return value; }
From source file:Main.java
public static String getAttr(Element e, String attr) { if (e.hasAttribute(attr)) { return e.getAttribute(attr); }//from w w w. jav a2 s .c om return null; }
From source file:Main.java
public static String getAttribute(Element e, String name, String defaultValue) { return (e.hasAttribute(name)) ? e.getAttribute(name) : defaultValue; }