List of usage examples for org.w3c.dom Element getAttribute
public String getAttribute(String name);
From source file:Main.java
/** * Parses the given attribute of this tag and returns it as a float *//* w w w . j a v a 2 s . co m*/ public static float getAttribFloat(Element ele, String name) { String sval = ele.getAttribute(name); float val = 0.0f; try { val = Float.parseFloat(sval); } catch (Exception e) { } return val; }
From source file:Main.java
/** * Returns the value of an attribute of a given XML element * //from w w w . j a v a 2 s . c om * @param element * A element * @param attributeName * The name of the attribute * @return The value of the attribute or <code>null</code> if no such * attribute exists */ public static String getAttributeValue(Element element, String attributeName) { return (null == element ? null : element.getAttribute(attributeName)); }
From source file:Main.java
public static String getTextAttribute(Element el, String attr, String defaultValue) { if (el.hasAttribute(attr)) { return el.getAttribute(attr); } else {/*from w w w . j a v a 2 s . co m*/ return defaultValue; } }
From source file:Main.java
public static boolean attributeBoolValue(Element e, String attr) { if (!e.hasAttribute(attr)) return false; String val = e.getAttribute(attr); return val.equals("yes") || val.equals("true") || val.equals("1"); }
From source file:Main.java
public static double getDoubleAttribute(Element node, String attr) { double retValue = 0; try {/*from ww w . j a v a 2 s.c o m*/ String s = node.getAttribute(attr); s = s.replace(',', '.'); //retValue = Double.parseDouble( s ); retValue = Double.valueOf(s).doubleValue(); } catch (NumberFormatException ex) { System.err.println("Parse error:" + ex.getMessage() + " while reading attr: " + attr); lastState = ERROR; } return retValue; }
From source file:Main.java
public static int readIntegerAttribute(Element elem, String name, int defaultValue) { int back = defaultValue; String str = elem.getAttribute(name); if (str != null) { if (str.length() > 0) { back = Integer.parseInt(str); }/*from w w w .ja v a 2 s .c om*/ } return back; }
From source file:Main.java
public static String getArg(final NodeList args, final String strName, final String strDefaultValue) { for (int i = 0; i < args.getLength(); ++i) { final Node node = args.item(i); if (node instanceof Element) { final Element arg = (Element) node; if (arg.getAttribute("name").equals(strName)) { return node.getLastChild().getTextContent().trim(); }// w ww. ja va2s. c om } } // end for return strDefaultValue; }
From source file:Main.java
public static int readIntAttr(Element element, String attributeName, int defaultValue) { String attributeValue = element.getAttribute(attributeName); try {/*from www . j a v a 2s . co m*/ return Integer.parseInt(attributeValue); } catch (NumberFormatException e) { return defaultValue; } }
From source file:Main.java
public static String readStringAttribute(Element elem, String name, String defaultValue) { String back = defaultValue;// www. j a va 2s .c o m String str = elem.getAttribute(name); if (str != null) if (str.length() > 0) { back = str; } return back; }
From source file:Main.java
public static Color readColorAttr(Element element, String attributeName, Color defaultValue) { String s = element.getAttribute(attributeName); if (s == null || s.charAt(0) != '#') { return defaultValue; }/*from w w w. j a va2 s.com*/ try { return new Color(Integer.parseInt(s.substring(1), 16), false); } catch (NumberFormatException e) { e.printStackTrace(); return defaultValue; } }