List of usage examples for org.w3c.dom Element getChildNodes
public NodeList getChildNodes();
NodeList
that contains all children of this node. From source file:Main.java
/** * Gets the children./*from w w w . j a v a2 s .co m*/ * * @param sourceElement * the source element * * @return the children */ public static List<Node> getChildren(Element sourceElement) { ArrayList<Node> children = new ArrayList<Node>(); NodeList nodeList = sourceElement.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node child = nodeList.item(i); children.add(child); } return children; }
From source file:Main.java
public static Map<String, String> getChildTextMap(Element elt) { Map<String, String> data = new HashMap<String, String>(); NodeList nodes = elt.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node child = nodes.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) child; data.put(e.getNodeName(), getInnerText(e)); }//from w w w. j ava 2s . com } return data; }
From source file:Main.java
public static final List<Element> getChildElements(Element parent) { final List<Element> childElements = new ArrayList<Element>(); final NodeList childNodes = parent.getChildNodes(); for (int i = 0; i < childNodes.getLength(); ++i) { final Node node = childNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { childElements.add((Element) node); }//from w ww . ja v a2 s. c o m } return childElements; }
From source file:Main.java
public static NodeList getChildsByTagName(Element root, String name) { final Vector<Node> v = new Vector<Node>(); NodeList nl = root.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i);// ww w. ja v a2 s . c o m if (n.getNodeType() == Element.ELEMENT_NODE) { Element e = (Element) n; if (name.equals("*") || e.getNodeName().equalsIgnoreCase(name)) v.add(n); } } return new NodeList() { public Node item(int index) { if (index >= v.size() || index < 0) return null; else return v.get(index); } public int getLength() { return v.size(); } }; }
From source file:Main.java
public static List<Element> getChildNodes(Element parent, String name) { List<Element> result = new ArrayList<Element>(); NodeList childNodes = parent.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node n = childNodes.item(i); if (name.equals(n.getNodeName())) { result.add((Element) n); }/*from w w w . j ava 2 s . com*/ } return result; }
From source file:Main.java
/** * Get element node string value.//from w w w .ja v a2 s . c o m * * @param element element to get string value for * @return concatenated text node descendant values */ public static String getStringValue(final Element element) { final StringBuilder buf = new StringBuilder(); final NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { final Node n = children.item(i); switch (n.getNodeType()) { case Node.TEXT_NODE: buf.append(n.getNodeValue()); break; case Node.ELEMENT_NODE: buf.append(getStringValue((Element) n)); break; } } return buf.toString(); }
From source file:Main.java
/** * Set the value of element//from w ww . j av a 2 s . co m * * @param element * @param val */ public static void setElementValue(Element element, String val) { Node node = element.getOwnerDocument().createTextNode(val); NodeList nl = element.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node nd = nl.item(i); if (nd.getNodeType() == Node.TEXT_NODE) { nd.setNodeValue(val); return; } } element.appendChild(node); }
From source file:Main.java
public static List<Element> getChildren(String name, Element e) { List<Element> result = new ArrayList<Element>(); if (e != null) { for (int i = 0; i < e.getChildNodes().getLength(); i++) { if (e.getChildNodes().item(i).getNodeName().equals(name)) { result.add((Element) e.getChildNodes().item(i)); }/* w w w .j a v a 2 s . c om*/ } } return result; }
From source file:Main.java
public static List<Element> getChildElementsNS(Element parent, String uri) { List<Element> ret = new ArrayList<Element>(); NodeList childList = parent.getChildNodes(); for (int i = 0; i < childList.getLength(); i++) { if (childList.item(i).getNodeType() != Node.ELEMENT_NODE) continue; Element child = (Element) childList.item(i); if (child.getNamespaceURI().equals(uri)) ret.add(child);//from w w w . j av a2 s .c om } return ret; }
From source file:Main.java
public static Element GetCustomer(JFrame mainFrame, long lookupValue, Document CustomerDoc) { Element Customer = null;/*from ww w . j ava 2s. co m*/ Element Root = CustomerDoc.getDocumentElement(); if (Root.hasChildNodes()) { NodeList Customers = Root.getChildNodes(); for (int i = 0; i < Customers.getLength(); i++) { if (Customers.item(i).getNodeName() == "#text") continue; Element Current = (Element) Customers.item(i); if (lookupValue == Integer.parseInt(Current.getAttribute("Id"))) { Customer = Current; } } } return Customer; }