List of utility methods to do XML First Child Element
String | firstChildTextContent(Element element, String name) first Child Text Content Element child = firstChild(element, name); if (child != null) { return child.getTextContent(); return null; |
Node | firstElementNodeChild(Node n) first Element Node Child Node m = n.getFirstChild(); while (m != null && !isElementNode(m)) m = m.getNextSibling(); return m; |
Element | firstNamedChild(Element el, String lName) return the first child of the element with given name, or null if there are none if (el == null) return null; Element fc = null; if (namedChildElements(el, lName).size() > 0) fc = namedChildElements(el, lName).elementAt(0); return fc; |
Text | firstTextChild(Element el) first Text Child Text text = null; for (int i = 0; i < el.getChildNodes().getLength(); i++) { Node n = el.getChildNodes().item(i); if (n instanceof Text) text = (Text) n; return text; |
Node | getDirectChild(Node fNode, String localName, String namespace) get Direct Child for (Node currentChild = fNode.getFirstChild(); currentChild != null; currentChild = currentChild .getNextSibling()) { if (localName.equals(currentChild.getLocalName()) && namespace.equals(currentChild.getNamespaceURI())) { return currentChild; return null; |
Node | getDirectChild(Node fNode, String localName, String namespace) get Direct Child for (Node currentChild = fNode.getFirstChild(); currentChild != null; currentChild = currentChild .getNextSibling()) { if ((namespace == null || namespace.equalsIgnoreCase(currentChild.getNamespaceURI())) && localName.equalsIgnoreCase(currentChild.getLocalName())) { return currentChild; return null; ... |
Element | getDirectChildElement(Element p_rootElement, String p_elementName) get Direct Child Element for (Node node = p_rootElement.getFirstChild(); node != null; node = node.getNextSibling()) { if (node.getNodeName().equalsIgnoreCase(p_elementName)) return (Element) node; return null; |
ArrayList | getDirectChildElements(Element parent) Returns a collection of direct child Elements ArrayList<Element> result = new ArrayList<Element>(); for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) { if (child instanceof Element) { result.add((Element) child); return result; |
List | getDirectChildElements(Node fNode, String localName, String namespace) Gets all direct children with specified localname and namespace. List<Element> children = new ArrayList<Element>(); for (Node currentChild = fNode.getFirstChild(); currentChild != null; currentChild = currentChild .getNextSibling()) { if (Node.ELEMENT_NODE == currentChild.getNodeType() && localName.equals(currentChild.getLocalName()) && namespace.equals(currentChild.getNamespaceURI())) { children.add((Element) currentChild); return children; |
List | getDirectChildElementsByTag(Element node, String tag) This method returns a list of the direct element node children of this element node with the specified tag. List<Element> children = new ArrayList<Element>(); Node child = node.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE && (child.getNodeName().equals(tag) || tag.equals(DOM_WILDCARD))) { children.add((Element) child); child = child.getNextSibling(); ... |