List of utility methods to do XML Node Text Value
String | getText(Node n) Returns the textual content directly held under this element as a string. String rtnVal = ""; NodeList nlist = n.getChildNodes(); Node currentNode; for (int i = 0; i < nlist.getLength(); i++) { currentNode = nlist.item(i); if (currentNode.getNodeType() == Node.TEXT_NODE) { rtnVal = currentNode.getNodeValue(); return rtnVal; |
String | getText(Node n) get Text StringBuffer sb = new StringBuffer(); for (Node ele = n.getFirstChild(); ele != null; ele = ele.getNextSibling()) { String name = ele.getNodeName(); if (name.equalsIgnoreCase("#text")) sb.append(ele.getNodeValue()); return sb.toString().trim(); |
String | getText(Node n) Gets the text for a node by concatenating child TEXT elements. if (n == null) throw new IllegalArgumentException("Node argument cannot be null"); StringBuilder b = new StringBuilder(); NodeList nl = n.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i).getNodeType() == Node.TEXT_NODE) b.append(nl.item(i).getNodeValue()); else if (nl.item(i).getNodeType() == Node.CDATA_SECTION_NODE) ... |
String | getText(Node nd) Drop in replacement for Node.getTextContent(). short type = nd.getNodeType(); switch (type) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_TYPE_NODE: case Node.NOTATION_NODE: return null; StringBuilder sb = new StringBuilder(); ... |
void | getText(Node nd, StringBuilder buf) get Text short type = nd.getNodeType(); switch (type) { case Node.ELEMENT_NODE: case Node.ENTITY_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.DOCUMENT_FRAGMENT_NODE: NodeList childs = nd.getChildNodes(); for (int i = 0; i < childs.getLength(); i++) { ... |
String | getText(Node node) Gets text for a node. NodeList children = node.getChildNodes(); int numChildren = children.getLength(); for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (child.getNodeType() == Node.TEXT_NODE) return child.getNodeValue().trim(); return ""; ... |
String | getText(Node node) Returns text content of a given Node. NodeList nodes = node.getChildNodes(); int len = nodes.getLength(); if (len == 0) { return null; StringBuilder text = new StringBuilder(); for (int i = 0; i < len; i++) { Node child = nodes.item(i); ... |
String | getText(Node node) get Text StringBuffer result = new StringBuffer(); NodeList nodes = node.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node2 = nodes.item(i); if (node2.getNodeType() == Node.TEXT_NODE || node2.getNodeType() == Node.CDATA_SECTION_NODE) { String value = node2.getNodeValue(); result.append(value); return result.toString().trim(); |
String | getText(Node node) get Text StringBuffer result = new StringBuffer(); if (!node.hasChildNodes()) { return ""; NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node subnode = list.item(i); if (subnode.getNodeType() == Node.TEXT_NODE) { ... |
String | getText(Node node) get Text StringBuffer result = new StringBuffer(); if (!node.hasChildNodes()) return ""; NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) Node subnode = list.item(i); if (subnode.getNodeType() == Node.TEXT_NODE) ... |