List of utility methods to do XML Attribute Get
String | getAttributeByName(Node content, String attributeName) Gets an attribute value by name, returning null if not found if (content != null) { NamedNodeMap atts = content.getAttributes(); if (atts == null) { return null; Node att = atts.getNamedItem(attributeName); if (att != null) { return att.getNodeValue(); ... |
boolean | getAttributeByName(Node node, String name, boolean defaultValue) Returns the value of a named node attribute in the form of a boolean if (node == null || name == null) return defaultValue; try { return getAttributeBooleanByName(node.getAttributes(), name); } catch (Exception e) { return defaultValue; |
String | getAttributeByName(Node node, String name, String defaultValue) Returns the attribute value for the passed name in the passed node. try { String val = getAttributeValueByName(node, name); if (val != null && !val.trim().isEmpty()) return val.trim(); } catch (Exception e) { return defaultValue; |
Optional | getAttributeContent(Node item, String attributeName) Gets the content of an attribute. NamedNodeMap attributes = item.getAttributes();
return Optional.ofNullable(attributes.getNamedItem(attributeName)).map(Node::getTextContent);
|
T | getAttributeEnum(Node node, String attributeName, Class get Attribute Enum return getAttributeEnum(node, attributeName, enumClass, null, false);
|
float | getAttributeFloatValue(String attribute, NamedNodeMap namedNodeMap) get Attribute Float Value String value = getAttributeStringValue(attribute, namedNodeMap); if (value != null) { return Float.parseFloat(value); return 0.0f; |
String | getAttributeFromClosestAncestorOfAnyKind(Node node, String attributeName) Climb through node 's ancestors, looking for one with an attribute named attributeName , irrespective of the respective ancestorName , and return the attribute's value
Node parentNode; while (node != null && (parentNode = node.getParentNode()) != null) { if (parentNode.hasAttributes()) { Element parentElement = (Element) parentNode; if (parentElement.hasAttribute(attributeName)) { return parentElement.getAttribute(attributeName); node = parentNode; return ""; |
Node | getAttributeIfExists(Node node, String name) get Attribute If Exists NamedNodeMap nnm = node.getAttributes();
return nnm.getNamedItem(name);
|
Attr | getAttributeIgnoreCase(Element element, String attributeName) Gets the DOM attribute of element with the given name.
NamedNodeMap nm = element.getAttributes(); for (int i = 0; i < nm.getLength(); i++) { Attr a = (Attr) nm.item(i); if (a.getName().equalsIgnoreCase(attributeName)) { return a; return null; ... |
String | getAttributeIgnoreCase(Element element, String string) get Attribute Ignore Case NamedNodeMap map = element.getAttributes(); for (int i = 0; i < map.getLength(); i++) { Node attr = map.item(i); if (string.equalsIgnoreCase(attr.getNodeName())) { return attr.getNodeValue(); return null; ... |