List of utility methods to do XML Attribute from Node
Integer | getIntAttributeValue(Node node, String attribute) get Int Attribute Value String value = getAttributeValue(node, attribute); if (value == null) return null; return Integer.parseInt(value); |
int | getIntAttrId(Node aNode, String aAttrName) Looks up the attr and returns the int of it or returns -1 String idStr = findAttrValue(aNode, aAttrName); if (idStr != null && idStr.length() > 0) { try { int id = Integer.parseInt(idStr); if (id > -1 && id < Integer.MAX_VALUE) { return id; } catch (NumberFormatException e) { ... |
Integer | getIntegerAttribute(Node n, String attributeName) get Integer Attribute Node attrib = n.getAttributes().getNamedItem(attributeName); if (attrib == null) return null; String value = attrib.getNodeValue(); assert (value != null); return new Integer(value); |
Integer | getIntegerAttribute(Node node, String att_name) Return the value of an attribute of a node as an integer number or null if the attribute is not present.
if (node == null) return null; String text = getText(node.getAttributes().getNamedItem(att_name)); if (text == null) return null; return Integer.valueOf(text); |
long | getLongAttributeByName(Node node, String name, long defaultValue) Returns the long attribute value for the passed name in the passed node. String s = getAttributeByName(node, name, null); if (s == null) return defaultValue; try { return Long.parseLong(s.trim()); } catch (Exception e) { return defaultValue; |
String | getLowerAttrValue(Node node, String attr) get Lower Attr Value String value = getAttrValue(node, attr); if (value != null) { return value.toLowerCase(); } else { return null; |
Element | getNextSiblingElement(Node node, String elemName, String attrName, String attrValue) Finds and returns the next sibling node with the given name and attribute name, value pair. Node sibling = node.getNextSibling(); while (sibling != null) { if (sibling.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) sibling; if (element.getNodeName().equals(elemName) && element.getAttribute(attrName).equals(attrValue)) { return element; sibling = sibling.getNextSibling(); return null; |
String | getNodeAttr(String attrName, Node node) Returns the value of the attribute for the given node. NamedNodeMap attrs = node.getAttributes(); for (int y = 0; y < attrs.getLength(); y++) { Node attr = attrs.item(y); if (attr.getNodeName().equalsIgnoreCase(attrName)) { return attr.getNodeValue(); return ""; ... |
String | getNodeAttr(String attrName, Node node) get Node Attr NamedNodeMap attrs = node.getAttributes(); for (int y = 0; y < attrs.getLength(); y++) { Node attr = attrs.item(y); if (attr.getNodeName().equalsIgnoreCase(attrName)) { return attr.getNodeValue(); return ""; ... |
String | getNodeAttr(String tagName, String attrName, NodeList nodes) get Node Attr for (int x = 0; x < nodes.getLength(); x++) { Node node = nodes.item(x); if (node.getNodeName().equalsIgnoreCase(tagName)) { NodeList childNodes = node.getChildNodes(); for (int y = 0; y < childNodes.getLength(); y++) { Node data = childNodes.item(y); if (data.getNodeType() == Node.ATTRIBUTE_NODE) { if (data.getNodeName().equalsIgnoreCase(attrName)) { ... |