List of utility methods to do XML First Child Element
Node | getFirstChildNodeWithName(String nodeName, Node parentNode) get First Child Node With Name parentNode.normalize(); NodeList childNodes = parentNode.getChildNodes(); Node resultNode = null; for (int i = 0; i < childNodes.getLength(); i++) { Node childElement = childNodes.item(i); if (childElement.getNodeName().equalsIgnoreCase(nodeName)) { resultNode = childElement; return resultNode; |
Element | getFirstChildOfTagName(Element elem, String name) get First Child Of Tag Name NodeList nodeList = elem.getChildNodes(); if (nodeList == null) { return null; for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node instanceof Element) { elem = (Element) node; ... |
Element | getFirstChildOfType(final Element elParent, final String childTag) Returns the first child element with the specified tag. for (Node childNode = elParent.getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) { if (childNode.getNodeType() == Node.ELEMENT_NODE) { final Element elChild = (Element) childNode; if (elChild.getTagName().equals(childTag)) { return elChild; return null; |
Element | getFirstChildTag(Element el, String tag) Method getFirstChildTag. NodeList nl; int len; nl = el.getChildNodes(); len = nl.getLength(); for (int i = 0; i < len; ++i) { Node n = nl.item(i); if (n instanceof Element) { Element elem = (Element) n; ... |
String | getFirstChildText(@Nullable final Node aStartNode) Get the content of the first Text child element of the passed element. if (aStartNode != null) { final NodeList aNodeList = aStartNode.getChildNodes(); final int nLen = aNodeList.getLength(); for (int i = 0; i < nLen; ++i) { final Node aNode = aNodeList.item(i); if (aNode instanceof Text) { final Text aText = (Text) aNode; if (!aText.isElementContentWhitespace()) ... |
Node | getFirstChildText(Node aNode) get First Child Text if (aNode == null) { return null; Node wNode = aNode.getFirstChild(); if (wNode == null || wNode.getNodeType() == Node.TEXT_NODE) { return wNode; } else { return getFirstSiblingElmt(wNode); ... |
Text | getFirstChildText(Node parent) Get the first Text child of the given parent. return getFirstChildImplementing(parent, Text.class); |
String | getFirstChildTextByTagName(Element element, String tagName) get First Child Text By Tag Name Element e = getFirstChildElementByTagName(element, tagName);
return e == null ? null : e.getTextContent().trim();
|
String | getFirstChildTextContent(Node node) get First Child Text Content String content = ""; if (node != null) { try { Node n = node.getFirstChild(); if (n != null) { content = n.getTextContent(); } catch (Exception e) { ... |
String | getFirstChildTextNodeValue(Node node) Returns value of first available child text node or null if not found.
NodeList children = node.getChildNodes(); int len = children.getLength(); for (int i = 0; i < len; i++) { Node n = children.item(i); if (n.getNodeType() == Node.TEXT_NODE) { return n.getNodeValue(); return null; |