List of utility methods to do XML Node Value
String | getValueByTagName(Node n, String tag) get Value By Tag Name if (n == null) return null; if (tag.equals(n.getLocalName())) return n.getFirstChild().getNodeValue(); if (n.hasChildNodes()) return getValueByTagName(n.getFirstChild(), tag); else if (n.getNextSibling() != null) return getValueByTagName(n.getNextSibling(), tag); ... |
String | getValueOfValueNode(Node n) Method to get the value of "Value" node NodeList textNodes = n.getChildNodes(); Node textNode; StringBuffer value = new StringBuffer(""); for (int j = 0; j < textNodes.getLength(); j++) { textNode = textNodes.item(j); value.append(textNode.getNodeValue()); return (value.toString().trim()); ... |
Node | getValues(Node metric) get Values return metric.getFirstChild().getNextSibling();
|
Double | nodeToDouble(Node node) Converts a node to a double Double returnValue = null; try { String nodeValue = node.getFirstChild().getNodeValue(); nodeValue = nodeValue.trim(); returnValue = nf.parse(nodeValue).doubleValue(); } catch (ParseException e) { e.printStackTrace(); return returnValue; |
void | putAll(final NamedNodeMap dst, final NamedNodeMap src) Puts all Nodes of the source NamedNodeMap into the destination NamedNodeMap final int size = size(src); for (int i = 0; i < size; i++) { dst.setNamedItemNS(src.item(i)); |
Text | setText(Element parent, String text) removes all element/text children, then adds a new single text child removeChildNodesExceptAttributes(parent);
Document doc = parent.getOwnerDocument();
Text child = doc.createTextNode(text);
parent.appendChild(child);
return child;
|
void | setText(Element parentNode, String data) Sets data to be the TEXT content of element if (data == null) return; Text txt = getTextNode(parentNode); if (txt != null) txt.setData(data); else { txt = parentNode.getOwnerDocument().createTextNode(data); parentNode.appendChild(txt); ... |
void | setText(Node n, String text) Sets the text for a node if (n == null) throw new IllegalArgumentException("Node argument cannot be null"); if (text == null) throw new IllegalArgumentException("Node text argument cannot be null"); NodeList nl = n.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i).getNodeType() == Node.TEXT_NODE) { nl.item(i).setNodeValue(text); ... |
Text | setText(Node node, String text) Creates a Text child, or replaces all existing children of type Text. NodeList children = node.getChildNodes(); if (children != null) { for (int i = 0, n = children.getLength(); i < n; ++i) { Node child = children.item(i); if (child instanceof Text) { return ((Text) child).replaceWholeText(text); Text ans = node.getOwnerDocument().createTextNode(text); node.appendChild(ans); return ans; |
void | setText(Node node, String text) set Text Text txt = node.getOwnerDocument().createTextNode(text); node.appendChild(txt); node.normalize(); |