List of usage examples for org.w3c.dom Element getElementsByTagName
public NodeList getElementsByTagName(String name);
NodeList
of all descendant Elements
with a given tag name, in document order. From source file:Main.java
public static Element getPropertyNode(Element properties, String name) { NodeList nodeList = properties.getElementsByTagName(PROPERTY_NODE); for (int i = 0; i < nodeList.getLength(); i++) { Element element = (Element) nodeList.item(i); if (name.equals(element.getAttributes().getNamedItem(NAME_ATTR).getNodeValue())) { return element; }//from w w w. j a v a2s . c om } return null; }
From source file:Main.java
public static List<Element> getChildNodes(Element parent, String name) { NodeList list = parent.getElementsByTagName(name); List<Element> children = new ArrayList<Element>(list.getLength()); for (int i = 0; i < list.getLength(); i++) { Node child = list.item(i); if (child.getNodeType() == 1) children.add((Element) child); }//from w ww. ja v a 2 s .co m return children; }
From source file:Main.java
public static boolean hasChildren(Element element, String childName) { NodeList ndLs = element.getElementsByTagName(childName); if (ndLs == null) return false; if (ndLs.getLength() > 0) return true; return false; }
From source file:Main.java
/** * Retrieves the first element, within the supplied element that has the specified tagName. * @param ele Parent element to search through * @param tagName Element name to find/*w w w . j a va2s. com*/ * @return Element within the parent element that has the specfied name, or null. */ public static Element getDistinctElementByName(Element ele, String tagName) { NodeList nl = ele.getElementsByTagName(tagName); if (nl != null && nl.getLength() > 0) { return (Element) nl.item(0); } return null; }
From source file:Main.java
public static final Boolean parameterExists(final Element e, final String name) { NodeList nl = e.getElementsByTagName(name); if (nl.getLength() > 0) { return true; } else {//from w w w .ja v a 2s . c o m return false; } }
From source file:Util.java
public static List<String> getTextValuesByTagName(Element element, String tagName) { NodeList nodeList = element.getElementsByTagName(tagName); ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < nodeList.getLength(); i++) { list.add(getTextValue(nodeList.item(i))); }/*w ww . j av a2s.co m*/ return list; }
From source file:Main.java
public static String getChildText(Element parent, String childName) { NodeList list = parent.getElementsByTagName(childName); if (list.getLength() > 1) { throw new IllegalStateException("Multiple child elements with name " + childName); } else if (list.getLength() == 0) { return null; }/*from w ww. j ava2 s . c om*/ Element child = (Element) list.item(0); return getText(child); }
From source file:Main.java
public static Vector<String> extractList(Element elem, String name) { NodeList nl = elem.getElementsByTagName(name); Vector<String> values = new Vector<String>(nl.getLength()); String retval = null;//www .ja va 2s . c o m for (int n = 0; n < nl.getLength(); n++) { Element element = (Element) nl.item(n); retval = getSimpleElementText(element); if (retval != null) values.addElement(retval); } return values; }
From source file:Main.java
public static NodeList extractNodeListFromElement(Element config, String tag, boolean required) { NodeList node = config.getElementsByTagName(tag); return check1Most(node, tag, required); }
From source file:Main.java
/** * Get a list of all child text Elements of given name directly * under a given {@code org.w3c.dom.Element}. * * @param elem the parent Element//from w w w . ja v a2s .com * @param name the given name of searched child Elements * @return a List of values of those child text Elements */ public static List<String> getAllElementsByTagName(Element elem, String name) { NodeList nodeList = elem.getElementsByTagName(name); List<String> result = new ArrayList<String>(); for (int i = 0; i < nodeList.getLength(); ++i) { NodeList children = nodeList.item(i).getChildNodes(); if (children.getLength() == 0 || children.item(0).getNodeType() != Node.TEXT_NODE) { continue; } result.add(children.item(0).getNodeValue()); } return result; }