List of utility methods to do XML Attribute from Node
String | getNodeAttributeValue(Node node, String attributeName) get Node Attribute Value return ((Element) node).getAttribute(attributeName);
|
String | getNodeAttributeValue(Node node, String attrName) get Node Attribute Value NamedNodeMap attrs = node.getAttributes(); if (attrs == null) return (null); Node value = attrs.getNamedItem(attrName); if (value == null) return (null); return (value.getNodeValue()); |
String | getNodeAttributeValueNS(Node node, String namespaceURI, String attrName) Gets attribute value of a node. NamedNodeMap attrs = node.getAttributes(); if (attrs == null) { return null; Node value = attrs.getNamedItemNS(namespaceURI, attrName); if (value == null) { return null; return value.getNodeValue(); |
Map | getNodeMap(NamedNodeMap artifactAttributes) get Node Map Map<String, String> attributeMap = new HashMap<String, String>(); if (artifactAttributes != null) { int attributeCount = artifactAttributes.getLength(); for (int idx = 0; idx < attributeCount; idx++) { Node attributeNode = artifactAttributes.item(idx); attributeMap.put(attributeNode.getNodeName(), attributeNode.getNodeValue()); return attributeMap; |
List | getNodesByAttributeValue(Node node, String attrName, String attrValue) Gets a list of nodes that matches the given attribute name and attribute value List<Node> list = new ArrayList<Node>(); NodeList nodeList = node.getChildNodes(); if (nodeList != null) { Node child; for (int i = 0; i < nodeList.getLength(); i++) { child = nodeList.item(i); if (nodeAttributeMatches(child, attrName, attrValue)) { list.add(child); ... |
String | getNonEmptyAttribute(Element element, String namespace, String localName) get Non Empty Attribute String value = element.getAttributeNS(namespace, localName); if (value == null || (value = value.trim()).length() == 0 || "???".equals(value)) { value = null; return value; |
String | getStringAttributeOptional(Node node, String attributeName, String valueIfEmpty) get String Attribute Optional NamedNodeMap attributes = node.getAttributes(); Node value = attributes.getNamedItem(attributeName); if (value == null) { return valueIfEmpty; String text = value.getTextContent(); if (text == null) { return valueIfEmpty; ... |
String | getStringAttributeRequired(Node node, String attributeName) get String Attribute Required NamedNodeMap attributes = node.getAttributes(); Node value = attributes.getNamedItem(attributeName); if (value == null) { throw new Exception("Missing attribute '" + attributeName + "' in node '" + node.getNodeName() + "'"); String text = value.getTextContent(); if (text == null) { throw new Exception("Missing text '" + attributeName + "' in node '" + node.getNodeName() + "'"); ... |
String | getValueForAttribute(Node currentNode, String attributeName) Get the value for the given attribute. NamedNodeMap attributes = currentNode.getAttributes(); String strCurrentModelName = null; if (attributes != null) { for (int i = 0; i < attributes.getLength(); i++) { Node node = attributes.item(i); if (node.getNodeName().equalsIgnoreCase(attributeName)) { strCurrentModelName = node.getNodeValue(); break; ... |
Date | getXMLDate(Element e, String attrName) get XML Date String s = e.getAttribute(attrName); if (s == null || s.length() == 0) return null; try { return parseDate(s); } catch (Exception exc) { return null; |