List of usage examples for org.w3c.dom Node getChildNodes
public NodeList getChildNodes();
NodeList
that contains all children of this node. From source file:Main.java
public static Vector getDirectories(Node node) { NodeList nList = node.getChildNodes(); Vector directoryNodes = new Vector(); for (int i = 0; i < nList.getLength(); i++) { Node kidNode = nList.item(i); if (kidNode.getNodeName().equals("directory")) { directoryNodes.addElement(kidNode); }//from w w w .j ava 2 s . com } return directoryNodes; }
From source file:Main.java
/** * Returns the content of the first CDATA section node found under the specified node. * /*from w w w .j a v a 2 s.c o m*/ * @param node * the node. * @return the content of the first CDATA section node. */ public static String getCDataSectionContent(Node node) { NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { if (list.item(i).getNodeType() == Document.CDATA_SECTION_NODE) { return list.item(i).getNodeValue(); } } return null; }
From source file:Main.java
public static void debugPrintChildren(Node node) { NodeList nl = node.getChildNodes(); System.out.println("-------------------"); for (int i = 0; i < nl.getLength(); i++) { System.out.println(nl.item(i).toString()); if (nl.item(i) instanceof Element) { System.out.println(((Element) nl.item(i)).getAttribute("className")); System.out.println(((Element) nl.item(i)).getTagName()); }/* w ww .j a v a 2 s . c om*/ System.out.println("---"); } }
From source file:Main.java
public static boolean hasChild(Node xml, String name) { NodeList nl = xml.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i);/*from w w w . j a v a 2 s . c o m*/ if (name.equalsIgnoreCase(n.getNodeName())) return true; } return false; }
From source file:Main.java
/** * Returns the text value of the specified node. The returned value is the node value of the first child of <code>node</code> which type * is <code>Document.TEXT_NODE</code>. * // w ww.j a v a 2s . c om * @param node * the node which text value has to be retrieved. * @return the text value of the node. */ public static String getTextValue(Node node) { NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { if (list.item(i).getNodeType() == Document.TEXT_NODE) { return list.item(i).getNodeValue(); } } return null; }
From source file:Main.java
public static void removeChilds(Node node) { NodeList nl = node.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) node.removeChild(nl.item(i));/*from w w w . j a v a2 s . c o m*/ }
From source file:Main.java
/** * Method to convert a Node XML to a Element XML. * @param node node XML to input./*w w w. j a v a 2s. c om*/ * @return elment XML. */ public static Element convertNodeToElement(Node node) { NodeList list = node.getChildNodes(); Element m = null; for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); //Node n = elem.getFirstChild(); if (n.getNodeType() == Node.ELEMENT_NODE) { m = (Element) n; } } return m; }
From source file:Utils.java
/** * Get the first child element/*from w ww . j a v a 2s . c om*/ * @param parent * @return */ public static Element getFirstChildElement(Node parent) { NodeList childs = parent.getChildNodes(); for (int i = 0; i < childs.getLength(); i++) { Node child = childs.item(i); if (child instanceof Element) { return (Element) child; } } return null; }
From source file:Main.java
private static String getXPath(Node root, String elementName) { for (int i = 0; i < root.getChildNodes().getLength(); i++) { Node node = root.getChildNodes().item(i); if (node instanceof Element == false) { return null; }//from ww w . j a v a 2s .co m if (node.getNodeName().equals(elementName)) { return "/" + node.getNodeName(); } else if (node.getChildNodes().getLength() > 0) { String xpath = getXPath(node, elementName); if (xpath != null) { return "/" + node.getNodeName() + xpath; } } } return null; }
From source file:Main.java
private final static boolean isParentNode(Node element) { NodeList elements = element.getChildNodes(); for (int i = 0; i < elements.getLength(); i++) { Node child = elements.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { return true; }/*ww w .j a va 2s .co m*/ } return false; }