List of utility methods to do XML Element Get Value
Element | getTagElement(Element node, String key) get Tag Element NodeList childs = node.getChildNodes(); for (int t = 0; t < childs.getLength(); t++) { Node attNode = childs.item(t); if (attNode.getAttributes() != null) { if (attNode.getAttributes().getNamedItem("k").getNodeValue().equals(key)) { return (Element) attNode; return null; |
String | getTagLocalName(final Element element) get Tag Local Name if (element == null) { return null; final String localName = element.getLocalName(); if (localName != null) { return localName; return element.getTagName(); ... |
String | getTagNameIgnorePrefix(Element element) get tag name without any prefix if (element == null) return null; String tagName = element.getTagName(); if (tagName.contains(":")) { tagName = tagName.split(":")[1]; return tagName; |
String | getTagText(Element ele) Scans the tag's children and returns the first text element found NodeList nl = ele.getChildNodes(); int size = nl.getLength(); Node node = null; int i = 0; for (; i < size; i++) { node = nl.item(i); if (node instanceof Text) break; ... |
String | getTagValue(Element e) Gets the text value from the specified element. Node n = (Node) e.getChildNodes().item(0); if (n == null) return null; return n.getNodeValue(); |
String | getTagValue(Element e, String tag) get Tag Value NodeList nlList = e.getElementsByTagName(tag).item(0).getChildNodes();
Node nValue = (Node) nlList.item(0);
return nValue.getNodeValue();
|
String | getTagValue(Element element, String tagName) get Tag Value String tagValue = ""; if (element != null) { NodeList nodes = element.getElementsByTagName(tagName); if (nodes != null && nodes.getLength() == 1) { Node node = nodes.item(0); tagValue = node.getTextContent(); return tagValue; |
String | getTagValue(Element element, String tagName) Retrieve the value of an XML tag. try { NodeList tagList = element.getElementsByTagName(tagName); Element tagElement = (Element) tagList.item(0); NodeList textTagList = tagElement.getChildNodes(); return (textTagList.item(0)).getNodeValue().trim(); } catch (Exception e) { throw new Exception( "Error in parsing the element \"" + element.toString() + "\" with the tag \"" + tagName + "\""); ... |
String | getText(Element aElement) Returns a concatenation of all of the text nodes and CDATA nodes that are immediate children of this element. if (aElement == null) return null; StringBuilder buffer = new StringBuilder(); NodeList nl = aElement.getChildNodes(); for (int i = 0; nl.item(i) != null; i++) { Node child = nl.item(i); switch (child.getNodeType()) { case Node.CDATA_SECTION_NODE: ... |
String | getText(Element config) returns the first text child within the node. if (config == null) { throw new IllegalArgumentException("config cannot be null"); NodeList children = config.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { if (children.item(i) instanceof Text) { return children.item(i).getNodeValue(); return null; |