List of utility methods to do XML First Child Element
Node | getFirstTextChild(Node n) Return the first text child node of a given node Returns null if there is no text child node NodeList children = n.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node currentChild = children.item(i); if (children.item(i).getNodeType() == Node.TEXT_NODE) { return currentChild; return null; ... |
String | getFirstTextChild(Node node) get First Text Child NodeList nodeList = node.getChildNodes(); if (nodeList != null) { for (int index = 0; index < nodeList.getLength(); index++) { Node child = nodeList.item(index); if (child.getNodeType() == Node.TEXT_NODE) { if (child.getNodeValue() != null && child.getNodeValue().trim().length() > 0) { return child.getNodeValue(); return null; |
Element | getFirstVisibleChildElement(Node parent) Finds and returns the first visible child element node. Node child = parent.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE && !isHidden(child)) { return (Element) child; child = child.getNextSibling(); return null; ... |
String | getValueOfFirstElementChild(final Element element, final String namespace, final String localname) get Value Of First Element Child Node node = getFirstElementChild(element, namespace, localname);
return (node == null) ? null : getNodeValue(node);
|
void | insertBeforeFirstChild(Element object, Element attrId) insert Before First Child if (object.hasChildNodes()) { object.insertBefore(attrId, object.getFirstChild()); } else { object.appendChild(attrId); |
Element | readFirstChild(Node parentNode, String nodeName) read First Child if (parentNode != null) { NodeList children = parentNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { if (children.item(i).getNodeName().equals(nodeName)) return (Element) children.item(i); return null; ... |
void | VectoriseFirstChildrenNodes(Node node, Vector elements) It creates a vector with contents all the first children of a node (without the node itself) NodeList list = node.getChildNodes(); if (list.getLength() > 0) for (int i = 0; i < list.getLength(); i++) elements.add(list.item(i)); |
Element | xmlFirstChild(final Element parent, final String childName, final boolean isThrow) Xml first child. final NodeList nodeList = parent.getChildNodes(); if (nodeList == null) { if (isThrow) { throw new IllegalArgumentException("nodeList == null"); return null; final int size = nodeList.getLength(); ... |