List of usage examples for org.w3c.dom Node getNodeName
public String getNodeName();
From source file:Main.java
public static List<Node> getChildElementsByTagName(Element ele, String childEleName) { NodeList nl = ele.getChildNodes(); List<Node> childEles = new ArrayList<Node>(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && childEleName.equals(node.getNodeName()) || childEleName.equals(node.getLocalName())) { childEles.add(node);//from www . j a va 2 s. c o m } } return childEles; }
From source file:Main.java
public static Node SearchNode(NodeList listNode, ArrayList<String> arrStrCompare) { ArrayList<String> arrTempList = arrStrCompare; Iterator<String> iterator = arrTempList.iterator(); while (iterator.hasNext()) { String strCompare = (String) iterator.next(); iterator.remove();/* ww w . j av a2 s . co m*/ for (int i = 0; i < listNode.getLength(); i++) { Node node = listNode.item(i); if (strCompare.equals(node.getNodeName())) { if (iterator.hasNext()) { return SearchNode(node.getChildNodes(), arrTempList); } String strResp = node.getTextContent(); System.out.println("Found DATA [" + strCompare + "]: " + strResp); return node; } } } return null; }
From source file:Main.java
public static String FindNode(NodeList listNode, ArrayList<String> arrStrCompare, String strData) { ArrayList<String> arrTempList = arrStrCompare; Iterator<String> iterator = arrTempList.iterator(); while (iterator.hasNext()) { String strCompare = (String) iterator.next(); iterator.remove();/*w ww . j av a2 s .c om*/ for (int i = 0; i < listNode.getLength(); i++) { Node node = listNode.item(i); if (strCompare.equals(node.getNodeName())) { if (iterator.hasNext()) { return FindNode(node.getChildNodes(), arrTempList, strData); } String strResp = node.getTextContent(); System.out.println("Found NODE [" + strCompare + "]: " + strResp); return strResp; } } } return null; }
From source file:Utils.java
/** * Search our next siblings for a given node * @param currentNode Starting point for our search * @param tagName Node name to look up// ww w. j a va2 s. c om * @return matching Node (null if none) */ public static Node getNextSiblingByName(Node currentNode, String tagName) { Node node = currentNode.getNextSibling(); while ((node != null) && (!node.getNodeName().equals(tagName))) { node = node.getNextSibling(); } return node; }
From source file:Main.java
public static Node getChild(Node parent, String nodename) { for (Node child : toList(parent.getChildNodes())) { if (child.getNodeName().equalsIgnoreCase(nodename)) { return child; }// ww w . j a v a2s . c o m } return null; }
From source file:Main.java
public static Element getChildElementByTagName(Element ele, String childEleName) { NodeList nl = ele.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && childEleName.equals(node.getNodeName()) || childEleName.equals(node.getLocalName())) { return (Element) node; }/* w w w .j a v a 2 s. com*/ } return null; }
From source file:Main.java
public static List getChildrenElement(Node n, String childTagName) { List lst = new ArrayList(); NodeList nl = n.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node cn = nl.item(i); if ((cn.getNodeType() == Node.ELEMENT_NODE) && (cn.getNodeName().equals(childTagName))) { lst.add(cn);//from www . j a va 2 s .c om } } return lst; }
From source file:Main.java
public static Node[] findNodesByTagName(Node parentNode, String tagName) { ArrayList<Node> nodes = new ArrayList<Node>(); for (int i = 0; i < parentNode.getChildNodes().getLength(); i++) { Node node = parentNode.getChildNodes().item(i); if (node.getNodeName().equals(tagName)) nodes.add(node);// w ww. j av a 2 s. c o m if (node.hasChildNodes()) { Node[] foundChildNodes = findNodesByTagName(node, tagName); for (int j = 0; j < foundChildNodes.length; j++) nodes.add(foundChildNodes[j]); } } Node[] returnNodes = new Node[nodes.size()]; return nodes.toArray(returnNodes); }
From source file:Main.java
public static Element getLocalElementByTagName(Element context, String tagName) { NodeList childNodes = context.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node instanceof Element && tagName.equals(node.getNodeName())) return (Element) node; }/* w ww .j a v a 2s. c o m*/ return null; }
From source file:Main.java
private static String getDate(Node node) { String date = ""; NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node curNode = nodeList.item(i); if ("date".equalsIgnoreCase(curNode.getNodeName())) { date = curNode.getTextContent().replace("\"", ""); break; }//from w w w . ja v a2 s .c om } return date; }