List of usage examples for org.w3c.dom Element getAttribute
public String getAttribute(String name);
From source file:Main.java
public static boolean getOptionalBoolean(Element element, String attribute, boolean defaultValue) { String s = element.getAttribute(attribute); if (s == null || "".equals(s)) { return defaultValue; } else {// w w w. ja v a2 s .c o m return Boolean.valueOf(s).booleanValue(); } }
From source file:Main.java
public static Integer getIntegerAttr(Element element, String name) { String attr = element.getAttribute(name); if (!attr.isEmpty()) { Integer ret = Integer.valueOf(attr); return ret; }// w w w. j a va 2 s.c o m return null; }
From source file:Main.java
public static Element getChildWithAttribute(Element parent, String attrName) { NodeList childNodes = parent.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node instanceof Element) { Element element = (Element) node; if (!"".equals(element.getAttribute(attrName))) { return element; }//from w w w .j av a 2 s . c o m } } return null; }
From source file:Main.java
private static Node actualFindNodeWithAttributeValue(Node node, String name, String attribute, String value) { String nodeName = node.getNodeName(); nodeName = nodeName.substring((nodeName.indexOf(":") != -1 ? nodeName.indexOf(":") + 1 : 0)); if (nodeName.equals(name)) { Element e = (Element) node; if (e.getAttribute(attribute) != null && e.getAttribute(attribute).equals(value)) return node; }//www . ja va 2 s. c om if (node.hasChildNodes()) { NodeList list = node.getChildNodes(); int size = list.getLength(); for (int i = 0; i < size; i++) { Node found = actualFindNodeWithAttributeValue(list.item(i), name, attribute, value); if (found != null) return found; } } return null; }
From source file:Main.java
public static int getXMLInt(Element e, String attrName) { try {/*from w w w . j a v a 2 s. c om*/ return Integer.parseInt(e.getAttribute(attrName)); } catch (Exception exc) { return -1; } }
From source file:Main.java
/** * Extract the node string representation. * //from w w w. j a v a2 s .c o m * @param nodeList * @return */ public static String getXmlNodeAttribute(String attributeName, NodeList nodeList) { String retObj = null; if (nodeList != null && nodeList.getLength() > 0) { Element element = (Element) nodeList.item(0); retObj = element.getAttribute(attributeName); } return retObj; }
From source file:Main.java
public static Element getChildByAttrName(Node node, String attrName, String attrValue) { NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node n = nodeList.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { Element el = (Element) n; if (attrValue.equals(el.getAttribute(attrName))) { return el; }//ww w . j a v a 2 s. c o m } } return null; }
From source file:Main.java
public static boolean isDitaType(Element element, String ditaMapType) { String classValue = element.getAttribute(DITA_CLASS_ATTNAME); if (classValue != null) { return (classValue.indexOf(" " + ditaMapType.trim() + " ") > 0 || classValue.endsWith(" " + ditaMapType.trim())); }//from www .j a v a2 s.c o m return false; }
From source file:Main.java
public static double getXMLNum(Element e, String attrName) { try {//from w w w.j a v a 2 s . c o m return Double.parseDouble(e.getAttribute(attrName)); } catch (Exception exc) { return 0; } }
From source file:Main.java
/** * @deprecated use getXPath instead!/*from w w w. j a v a 2 s .c om*/ */ @Deprecated public static Element getElementByAttribute(Element root, String tagname, String attribute, String att_value) { NodeList nl = root.getElementsByTagName(tagname); for (int i = 0; i < nl.getLength(); i++) { Element elem = (Element) nl.item(i); if (elem.getAttribute(attribute).equals(att_value)) { return elem; } } return null; }