List of utility methods to do XML Element Get Value
List | getTextList(Element elem, String name) get Text List List<String> result = new ArrayList<String>(); List<Element> childElements = getChildElementsByTagName(elem, name); for (Element childElem : childElements) { Node node = childElem.getFirstChild(); result.add(node == null ? "" : node.getTextContent()); return result; |
String | getTextOfElement(Element e) Returns the content of all text nodes underneath a specified Element , concatenated together into a single string.
NodeList kids = e.getChildNodes(); if (kids == null) return null; StringBuffer b = null; for (int i = 0; i < kids.getLength(); i++) { Node t = kids.item(i); if ((t.getNodeType() == Node.TEXT_NODE) || (t.getNodeType() == Node.CDATA_SECTION_NODE)) { if (b == null) ... |
String[] | getTexts(Element root, String elementName) get Texts NodeList list = root.getElementsByTagName(elementName); String[] ret = new String[list.getLength()]; for (int i = 0; i < list.getLength(); i++) { Text txt = (Text) list.item(i).getFirstChild(); if (txt != null) { ret[i] = txt.getData(); } else { ret[i] = ""; ... |
String | getTextString(Element e) Get the text of a text (simple content) element. String s = getText(e); return s == null ? "" : s; |
String | getTextTrim(Element element) get Text Trim Node node = element.getChildNodes().item(0); if (node != null && node.getNodeType() == Node.TEXT_NODE) return node.getNodeValue().trim(); return ""; |
String | getTextTrim(Element element) get Text Trim String txt = getText(element);
return (txt == null) ? txt : txt.trim();
|
String | getTextValue(Element el, String tagName) get Text Value String textVal = null; NodeList nl = el.getElementsByTagName(tagName); if (nl != null && nl.getLength() > 0) { Element e = (Element) nl.item(0); textVal = e.getFirstChild().getNodeValue(); return textVal; |
String | getTextValue(Element ele, String tagName) Returns the value of given tagName under given element. String textVal = null; try { NodeList nl = ele.getElementsByTagName(tagName); if (nl != null && nl.getLength() > 0) { Element el = (Element) nl.item(0); Node firstChild = el.getFirstChild(); if (firstChild != null) textVal = firstChild.getNodeValue(); ... |
String | getTextValue(Element ele, String tagName) Returns text value of first element in specified element with specified tag. String textVal = null; List<Element> nl = getChildren(ele, tagName); if (nl != null && nl.size() != 0) { Element el = nl.get(0); textVal = getValue(el); if (textVal != null) { textVal = textVal.trim(); if (textVal.equalsIgnoreCase("")) { ... |
String | getTextValue(Element ele, String tagName) get Text Value String textVal = null; NodeList nl = ele.getElementsByTagName(tagName); if (nl != null && nl.getLength() > 0) { Element el = (Element) nl.item(0); textVal = el.getFirstChild().getNodeValue(); return textVal; |