List of utility methods to do XML First Child Element
String | getDirectChildElementValue(Element p_rootElement, String p_elementName) get Direct Child Element Value Element element = getDirectChildElement(p_rootElement, p_elementName); if (element == null) return null; return getElementValue(element); |
List | getDirectChildElementValues(Element p_rootElement, String p_elementName) get Direct Child Element Values List result = new ArrayList(); List elems = getChildElements(p_rootElement, p_elementName); for (Iterator itor = elems.iterator(); itor.hasNext();) { Element elem = (Element) itor.next(); result.add(getElementValue(elem)); return result; |
ArrayList | getDirectChildNamedElements(Element parent, String name) Returns a collection of direct child Elements that match the specified tag name ArrayList<Element> result = new ArrayList<Element>(); for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) { if (child instanceof Element && name.equals(child.getNodeName())) { result.add((Element) child); return result; |
Node | getDirectChildNode(Node node, String name) get Direct Child Node Node targetNode = null; List<Node> nodes = getDirectChildNodes(node, name); if (nodes.size() == 1) { targetNode = nodes.get(0); return targetNode; |
List | getDirectChildNodes(final Node parent, final String... nodeNames) Scans a node for directly related child nodes of a particular type. return getChildNodes(parent, false, nodeNames);
|
List | getDirectChildNodes(Node node, String name) get Direct Child Nodes LinkedList<Node> nodes = new LinkedList<Node>(); NodeList childList = node.getChildNodes(); for (int childIndex = 0; childIndex < childList.getLength(); childIndex++) { Node child = childList.item(childIndex); if (child.getNodeName().equals(name)) { nodes.add(child); return nodes; |
Element | getFirstChild(Element e) get First Child if (e == null) return null; Node n = e.getFirstChild(); while (n != null && n.getNodeType() != Node.ELEMENT_NODE) n = n.getNextSibling(); return (Element) n; |
Element | getFirstChild(Element e, String nsUri, String local) Gets the first child of the given name, or null. for (Node n = e.getFirstChild(); n != null; n = n.getNextSibling()) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element c = (Element) n; if (c.getLocalName().equals(local) && c.getNamespaceURI().equals(nsUri)) return c; return null; ... |
Element | getFirstChild(Element elem, String childTag) get First Child if (elem.hasChildNodes()) { NodeList list = elem.getElementsByTagName(childTag); int count = list.getLength(); for (int i = 0; i < count; i++) { Node node = list.item(i); if (node.getParentNode() != elem) continue; if (node.getNodeType() == Node.ELEMENT_NODE) { ... |
Element | getFirstChild(Element element) get First Child NodeList nodelist = element.getChildNodes(); for (int i = 0; i < nodelist.getLength(); i++) { Node node = nodelist.item(i); if (node instanceof Element) return (Element) node; return null; |