List of utility methods to do XML Node Text Value
String | getTextContent(Node node, String path) Get the text content of an element identified by a path, where the path elements can include an index. if (node instanceof Document) node = ((Document) node).getDocumentElement(); if (!(node instanceof Element)) return ""; Element el = (Element) node; path = path.replaceAll("\\s", ""); if (path.startsWith("/")) path = path.substring(1); ... |
String | getTextContent(org.w3c.dom.Node element) return the text content of an element StringBuffer childtext = new StringBuffer(); NodeList childlist = element.getChildNodes(); int ct = childlist.getLength(); for (int j = 0; j < ct; j++) { org.w3c.dom.Node childNode = childlist.item(j); if ((childNode.getNodeType() == Node.TEXT_NODE) || (childNode.getNodeType() == Node.CDATA_SECTION_NODE)) { childtext.append(childNode.getNodeValue().trim()); ... |
String | getTextContentOld(final Node node) get Text Content Old final Node child = node.getFirstChild(); if (child != null) { final Node next = child.getNextSibling(); if (next == null) { return hasTextContent(child) ? child.getNodeValue() : ""; final StringBuilder buf = new StringBuilder(); appendTextContents(node, buf); ... |
String | getTextContents(Node node) (A useful utility method from IBM developerworks) NodeList childNodes; StringBuffer contents = new StringBuffer(); childNodes = node.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { if (childNodes.item(i).getNodeType() == Node.TEXT_NODE) { contents.append(childNodes.item(i).getNodeValue()); return contents.toString(); |
String | getTextData(Node element) Gets a TEXT node value from the specified Element node. if (element.getNodeType() != Node.ELEMENT_NODE) { throw new IllegalArgumentException(element + " is not ELEMENT node"); Node description = element.getNextSibling(); if (description.getNodeType() != Node.TEXT_NODE) { throw new IllegalArgumentException(description + " is not TEXT node"); return description.getNodeValue(); ... |
String | getTextData(Node node) get Text Data if (!node.hasChildNodes()) { return null; Node child = node.getFirstChild(); while (child != null && child.getNodeType() != Node.TEXT_NODE && child.getNodeType() != Node.CDATA_SECTION_NODE) { child = child.getNextSibling(); if (child == null) { return null; if (child.getNodeType() == Node.TEXT_NODE) { return ((Text) child).getData(); } else { return ((CDATASection) child).getData(); |
String | getTextForNode(Node node) get Text For Node StringBuilder sb = new StringBuilder(); NodeList children = node.getChildNodes(); if (children.getLength() == 0) return null; for (int i = 0; i < children.getLength(); ++i) { Node n = children.item(i); if (n instanceof Text) sb.append(n.getNodeValue()); ... |
String | getTextForNode(Node node) get Text For Node StringBuffer sb = new StringBuffer(); NodeList children = node.getChildNodes(); if (children.getLength() == 0) return null; for (int i = 0; i < children.getLength(); ++i) { Node n = children.item(i); if (n instanceof Text) sb.append(n.getNodeValue()); ... |
String | getTextForNode(Node node) Gets the String value of the node. NodeList children = node.getChildNodes(); if (children == null) { return ""; for (int i = 0; i < children.getLength(); i++) { Node childNode = children.item(i); if ((childNode.getNodeType() == Node.TEXT_NODE) || (childNode.getNodeType() == Node.CDATA_SECTION_NODE)) { ... |
String | getTextFromNode(Node node, String defaultValue) get Text From Node if (node == null) { return defaultValue; if (node.getNodeType() == Node.ATTRIBUTE_NODE) { return ((Attr) node).getValue(); } else if (node.getNodeType() == Node.TEXT_NODE) { return node.getNodeValue(); } else { ... |