List of usage examples for org.w3c.dom Element getChildNodes
public NodeList getChildNodes();
NodeList
that contains all children of this node. From source file:com.weibo.wesync.notify.xml.DomUtils.java
/** * Utility method that returns the first child element identified by its name. * * @param ele the DOM element to analyze * @param childEleName the child element name to look for * @return the <code>org.w3c.dom.Element</code> instance, or <code>null</code> if none found *///from w w w.j a v a2 s . co m public static Element getChildElementByTagName(Element ele, String childEleName) { Assert.notNull(ele, "Element must not be null"); Assert.notNull(childEleName, "Element name must not be null"); NodeList nl = ele.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && nodeNameMatch(node, childEleName)) { return (Element) node; } } return null; }
From source file:com.msopentech.odatajclient.engine.utils.XMLUtils.java
/** * Gets the given node's children with the given name. * * @param node parent./*from w ww.jav a2 s . co m*/ * @param name searched child name. * @return children. */ public static List<Element> getChildElements(final Element node, final String name) { final List<Element> result = new ArrayList<Element>(); if (StringUtils.isNotBlank(name)) { final NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { final Node child = children.item(i); if ((child instanceof Element) && name.equals(child.getNodeName())) { result.add((Element) child); } } } return result; }
From source file:com.wso2telco.identity.application.authentication.endpoint.util.TenantDataManager.java
private static void refreshActiveTenantDomainsList() { try {/*from w w w .j a v a 2 s . c o m*/ String url = "https://" + getPropertyValue(HOST) + ":" + getPropertyValue(PORT) + "/services/TenantMgtAdminService/retrieveTenants"; String xmlString = getServiceResponse(url); if (xmlString != null && !"".equals(xmlString)) { XPathFactory xpf = XPathFactory.newInstance(); XPath xpath = xpf.newXPath(); InputSource inputSource = new InputSource(new StringReader(xmlString)); String xPathExpression = "/*[local-name() = '" + RETRIEVE_TENANTS_RESPONSE + "']/*[local-name() = '" + RETURN + "']"; NodeList nodeList = (NodeList) xpath.evaluate(xPathExpression, inputSource, XPathConstants.NODESET); tenantDomainList = new ArrayList<String>(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node != null && node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; NodeList tenantData = element.getChildNodes(); boolean activeChecked = false; boolean domainChecked = false; boolean isActive = false; String tenantDomain = null; for (int j = 0; j < tenantData.getLength(); j++) { Node dataItem = tenantData.item(j); String localName = dataItem.getLocalName(); if (ACTIVE.equals(localName)) { activeChecked = true; if ("true".equals(dataItem.getTextContent())) { isActive = true; } } if (TENANT_DOMAIN.equals(localName)) { domainChecked = true; tenantDomain = dataItem.getTextContent(); } if (activeChecked && domainChecked) { if (isActive) { tenantDomainList.add(tenantDomain); } break; } } } } Collections.sort(tenantDomainList); } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("Retrieving Active Tenant Domains Failed. Ignore this if there are no tenants : ", e); } } }
From source file:org.apache.ftpserver.config.spring.SpringUtil.java
/** * Get all child elements for the element * // w w w .j a v a2 s .c o m * @param elm * The element for which to locate children * @return All children */ public static List<Element> getChildElements(final Element elm) { List<Element> elements = new ArrayList<Element>(); NodeList childs = elm.getChildNodes(); for (int i = 0; i < childs.getLength(); i++) { Node child = childs.item(i); if (child instanceof Element) { elements.add((Element) child); } } return elements; }
From source file:DomUtil.java
/** * Returns the text content of a DOM <code>Element</code>. * /*from w ww . ja v a2 s . co m*/ * @param element The <code>Element</code> to analyze. */ public static String getElementText(Element element) { NodeList children = element.getChildNodes(); int childCount = children.getLength(); for (int index = 0; index < childCount; ++index) { if (children.item(index) instanceof Text) { Text text = (Text) children.item(index); return text.getData(); } } return null; }
From source file:Main.java
public static Collection<Element> fetchSubElements(Element e, String subElementName) { if (e == null || subElementName == null) { return null; }/*from www.j a v a2s .com*/ subElementName = subElementName.toUpperCase(); Collection<Element> elements = new ArrayList<Element>(); NodeList list = e.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { if (list.item(i) instanceof Element) { Element element = (Element) list.item(i); if (element.getTagName().toUpperCase().equals(subElementName)) { elements.add(element); } } } return elements; }
From source file:Main.java
public static List<String> getAllLeaveValues(Element element) throws XPathExpressionException { if (element == null) { return null; }/* www . jav a 2s . c o m*/ List<String> ret = new LinkedList<String>(); if (isLeaf(element)) { ret.add(element.getTextContent()); } else { NodeList nl = element.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (n instanceof Element) { Element childElement = (Element) n; for (String childText : getAllLeaveValues(childElement)) { ret.add(childText); } } } } return ret; }
From source file:Main.java
static public ArrayList<Element> selectElements(Element element, String xpathExpression) throws XPathExpressionException { ArrayList<Element> resultVector = new ArrayList<Element>(); if (element == null) { return resultVector; }// www . j a va 2 s . c o m if (xpathExpression.indexOf("/") == -1) { NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(xpathExpression)) { resultVector.add((Element) node); } } } else { XPath xpath = XPathFactory.newInstance().newXPath(); NodeList nodes = (NodeList) xpath.evaluate(xpathExpression, element, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); resultVector.add((Element) node); } } return resultVector; }
From source file:DomUtil.java
/** * Retrieves the first immediate child element of the specified element * whose name matches the provided <code>name</code> parameter. * /*from w w w . j a v a 2s .c o m*/ * @param parentElement The element to search. * @param name The name of the child element. * @return The child element, or null if none was found. */ public static Element getChildElementByTagName(Element parentElement, String name) { NodeList nodes = parentElement.getChildNodes(); int length = nodes.getLength(); for (int index = 0; index < length; ++index) { if (nodes.item(index).getNodeType() == Node.ELEMENT_NODE && name.equals(nodes.item(index).getNodeName())) { return (Element) nodes.item(index); } } return null; }
From source file:DomUtil.java
/** * Sets the text content of a DOM <code>Element</code>. * /* w w w. j a v a 2 s . co m*/ * @param element The <code>Element</code> to modify. * @param value The new text value. */ public static void setElementText(Element element, String value) { NodeList children = element.getChildNodes(); int childCount = children.getLength(); for (int index = 0; index < childCount; ++index) { if (children.item(index) instanceof Text) { Text text = (Text) children.item(index); text.setData(value); return; } } Text text = element.getOwnerDocument().createTextNode(value); element.appendChild(text); }