List of utility methods to do XML Element Get
Element | getElement(Element element, boolean before) get Element NodeList bas = element.getParentNode().getChildNodes(); Element searchedElement = null; boolean found = false; for (int i = 0; i < bas.getLength() && (searchedElement == null || !found); i++) { if (element.equals(bas.item(i))) found = true; else if (bas.item(i) instanceof Element) { if (before && !found) ... |
Element | getElement(Element element, String name) Return the first named Element found. NodeList nodeList = getElementList(element, name);
return (nodeList.getLength() == 0) ? null : (Element) nodeList.item(0);
|
Element | getElement(Element element, String name, int index) get Element return (Element) element.getElementsByTagName(name).item(index);
|
Element | getElement(Element element, String tag) get Element NodeList nodes = element.getElementsByTagName(tag); if (nodes != null && nodes.getLength() > 0) { Element childElement = (Element) nodes.item(0); String nodeName = null; if (childElement != null) { nodeName = childElement.getNodeName(); if (nodeName != null && nodeName.compareTo(tag) == 0) { ... |
Element | getElement(Element element, String tagName) get Element final NodeList nodeList = element.getElementsByTagName(tagName); if (nodeList == null || nodeList.getLength() < 1) { return null; int length = nodeList.getLength(); for (int i = 0; i < length; i++) { Element childEle = (Element) nodeList.item(i); if (childEle == null || childEle.getParentNode() == element) { ... |
Element | getElement(Element element, String tagName, String namespace) get Element NodeList nodes = element.getElementsByTagNameNS(namespace, tagName); if (nodes.getLength() > 0) { return ((Element) nodes.item(0)); } else { return null; |
Element | getElement(Element root, String name) Get the first child element of the specified (root) element that has the specified name. if (root == null || name == null || name.length() <= 0) throw new IllegalArgumentException("Null or invalid argument passed to XmlUtil.getElement()"); NodeList lst = root.getChildNodes(); int size = lst.getLength(); name = localName(name); for (int i = 0; i < size; i++) { Node node = lst.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { ... |
Element | getElement(final Document doc, final String expression) Get one element from XML document using xpath expression if (null == expression || expression.isEmpty() || null == doc) { return null; log.finer("Executing xpath xpression " + expression); XPath xPath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xPath.compile(expression); Object result = expr.evaluate(doc, XPathConstants.NODE); return (Element) result; ... |
SOAPElement | getElement(SOAPMessage message, String tagname, String nsURI, int whichOne) Get a SOAP Element from the SOAPMessage (SOAPbody inside). if (message == null) return null; SOAPBody elementBody = message.getSOAPPart().getEnvelope().getBody(); if (elementBody == null) return null; NodeList nl = elementBody.getElementsByTagNameNS(nsURI, tagname); if (nl.getLength() <= whichOne) { return null; ... |
Element[] | getElementArray(Element config, String elementName) get Element Array NodeList children = config.getChildNodes(); Node node; ArrayList arrayList = new ArrayList(); for (int counter = 0; counter < children.getLength(); counter++) { node = children.item(counter); if (node instanceof Element) { if (((Element) node).getTagName().equals(elementName)) { arrayList.add(node); ... |