List of utility methods to do XML Element Child Get
Element | findNextSiblingElement(Element current) find Next Sibling Element org.w3c.dom.Node ret = current.getNextSibling(); while (ret != null) { if (ret instanceof Element) { return (Element) ret; ret = ret.getNextSibling(); return null; ... |
Element | GetElement(Element root, String namespaceUri, String name, boolean throwIfNotFound) Get Element NodeList nodes = root.getElementsByTagNameNS(namespaceUri, name); if (nodes.getLength() > 0) return (Element) nodes.item(0); else { if (throwIfNotFound) throw new Exception( String.format( "A node with name '%s' in namespace '%s' was not found.", ... |
ArrayList | getListContent(Element listElement, String listItemName, String listItemNamespace) Get list content for the given XML element, of the form if (listElement == null) { throw new IllegalArgumentException("listElement cannot be null"); if (listItemName == null || listItemName.length() == 0) { throw new IllegalArgumentException( "listItemName cannot be null or empty"); if (listItemNamespace == null) { ... |
String | getStringFromXml(Element validate, Boolean hasHeader) get String From Xml final String header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = null; try { transformer = transFactory.newTransformer(); } catch (TransformerConfigurationException e) { e.printStackTrace(); StringWriter buffer = new StringWriter(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); try { transformer.transform(new DOMSource(validate), new StreamResult(buffer)); } catch (TransformerException e) { e.printStackTrace(); String s = buffer.toString(); if (hasHeader) { return header + s; return s; |