List of utility methods to do XML Attribute Get
String | getAttributeValueOrNull(NamedNodeMap attributes, String attributeName) Given a list of attributes (from an XML element) and the particular attribute we are concerned with, return it's value. String returnValue = null; Node namedItem = attributes.getNamedItem(attributeName); if (namedItem != null) { returnValue = namedItem.getNodeValue(); return returnValue; |
Set | getAttributeValuePair(Node node) Method to get Values within AttributeValuePair as a java.util.Set if (!node.getNodeName().equals(ATTR_VALUE_PAIR_NODE)) return (null); Set retVal = new HashSet(); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node n = children.item(i); if (n.getNodeName().equalsIgnoreCase(VALUE_NODE)) { retVal.add(getValueOfValueNode(n)); ... |
String[] | getAttributeValues(Element el) Gets a list of all attribute values for the given DOM element. NamedNodeMap map = el.getAttributes(); int len = map.getLength(); String[] attrValues = new String[len]; for (int i = 0; i < len; i++) { Attr attr = (Attr) map.item(i); attrValues[i] = attr == null ? null : attr.getValue(); return attrValues; ... |
String[] | getAttributeValues(Node node, String nodeName, String attrName) Get an array of specific attributes for specific elements in a Node tree. if (node instanceof Document) node = ((Document) node).getDocumentElement(); if (!(node instanceof Element)) return new String[0]; NodeList nodeList = ((Element) node).getElementsByTagName(nodeName); ArrayList list = new ArrayList(); for (int i = 0; i < nodeList.getLength(); i++) { Attr attr = ((Element) nodeList.item(i)).getAttributeNode(attrName); ... |
String | getAttributeWithInheritance(Element element, String attributeName) Returns an attribute value from this node, or first parent node with this attribute defined String result = element.getAttribute(attributeName); if ((result == null) || ("".equals(result))) { Node n = element.getParentNode(); if ((n == element) || (n == null)) { return null; if (n instanceof Element) { Element parent = (Element) n; ... |
Object | getAttributName(Node node) get Attribut Name return node.getAttributes().getNamedItem(ATTRIBUT_NAME_ATTRIBUT).getNodeValue();
|
String | getAttributValue(Node n, String name) get Attribut Value if (n == null) return null; NamedNodeMap att = n.getAttributes(); if (att == null) return null; Node n2 = att.getNamedItem(name); if (n2 == null) return null; ... |
int | getAttrInt(Element root, String attrName) Get the value of the specified attribute as an integer. if (root.hasAttribute(attrName)) return Integer.valueOf(root.getAttribute(attrName)).intValue(); return 0; |
Map | getAttrList(Node node) get Attr List Map<String, String> map = new HashMap<String, String>(); NamedNodeMap list = node.getAttributes(); if (list != null) for (int i = 0; i < list.getLength(); i++) { Attr attr = (Attr) list.item(i); map.put(attr.getName(), attr.getValue()); return map; ... |
QName | getAttrName(String prefix, String name) get Attr Name if (prefix == null || "".equals(prefix)) { return new QName(name); } else { return new QName(prefix + Character.toUpperCase(name.charAt(0)) + name.substring(1)); |