List of utility methods to do XML Node Child Get
String | getChildTagValue(Node node, String tag) get Child Tag Value Element element = (Element) node;
NodeList childrenWithTag = element.getElementsByTagName(tag)
.item(0).getChildNodes();
Node valueNode = (Node) childrenWithTag.item(0);
return valueNode.getNodeValue();
|
String | getChildText(Node n) get Child Text StringBuffer str = new StringBuffer(); NodeList nl = n.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node c = nl.item(i); if (c.getNodeType() == Node.TEXT_NODE) { str.append(c.getNodeValue()); return str.toString(); |
List | getChildren(Node node, String name) get Children List<Node> children = new ArrayList<Node>(); NodeList nodes = node.getChildNodes(); if (nodes != null && nodes.getLength() >= 1) { for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); if (name.equals(n.getNodeName())) { children.add(n); return children; |
List | getChildren(Node node, String name) get Children List<Node> children = new ArrayList<Node>(); NodeList nodes = node.getChildNodes(); if (nodes != null && nodes.getLength() >= 1) { for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); if (name.equals(n.getNodeName())) { children.add(n); return children; |
List | getChildren(Node node, String name) get Children List<Node> children = new ArrayList<Node>(); NodeList nodes = node.getChildNodes(); if (nodes != null && nodes.getLength() > 0) { for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); if (name.equals(n.getNodeName())) { children.add(n); return children; |
List | getChildrenOfName(Node node, String name) get Children Of Name List<Node> res = new ArrayList<Node>(); NodeList childNodes = node.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node item = childNodes.item(i); String localName = item.getNodeName(); if (name.equals(localName)) { res.add(item); return res; |
Node | getFirstChild(Node node, String namespace, String name) Return the first child of a node, based on name/namespace. NodeList childNodes = node.getChildNodes(); for (int i = 0, l = childNodes.getLength(); i < l; i++) { Node child = childNodes.item(i); if (isInstance(child, namespace, name)) { return child; return null; ... |
Node | getFirstChild(Node node, String xmlLocalName) Returns the first child element with the given XML local name. String nsUri = node.getNamespaceURI(); for (Node child = node.getFirstChild(); child != null; child = child .getNextSibling()) { if (child.getNodeType() == Node.ELEMENT_NODE && nsUri.equals(child.getNamespaceURI())) { if (xmlLocalName == null || xmlLocalName.equals(child.getLocalName())) { return child; ... |
Node | getFirstMatchingChildNode(Node node, String nodeName) get First Matching Child Node return getFirstMatchingChildNode(node, nodeName, null, null);
|
Node | getFirstMatchingChildNode(Node node, String nodeName, String attributeName, List get First Matching Child Node if (node == null || nodeName == null) { return null; List<Node> nodes = getMatchingChildNodes(node, nodeName, attributeName, attributeValues); return (nodes == null || nodes.isEmpty()) ? null : (Node) nodes .get(0); |