List of utility methods to do XML String Transform
String | toLCCNDisplay(String packedLCCN) Convert a packed LCCN String to MARC display format. StringBuffer sb = new StringBuffer(); if (Character.isDigit(packedLCCN.charAt(2))) { sb.append(packedLCCN.substring(0, 2).trim()); sb.append(packedLCCN.substring(2, 6)); sb.append("-"); int i = Integer.parseInt(packedLCCN.substring(6).trim()); sb.append(Integer.toString(i)); } else { ... |
Integer | tomcatPort(String fileName) tomcat Port String xpathExpression = "/Server/Service/Connector[@protocol='HTTP/1.1']/@port"; String value = string(fileName, xpathExpression); try { int parseInt = Integer.parseInt(value); return parseInt; } catch (NumberFormatException e) { e.printStackTrace(); return null; ... |
String | toString(Collection Converts collection to a separated string. StringBuffer b = new StringBuffer(); for (Iterator<String> iter = c.iterator(); iter.hasNext();) { b.append(iter.next()); b.append(separator); if (c.size() > 0) { b.delete(b.length() - separator.length(), b.length()); return b.toString(); |
String | toString(Source input) Adapter method used to convert any type of Source to a String if (input == null) return null; StringWriter writer = new StringWriter(); Transformer trasformer; try { trasformer = TransformerFactory.newInstance().newTransformer(); Result result = new StreamResult(writer); trasformer.transform(input, result); ... |
void | write(Node node, OutputStream out, String... props) Writes a node to an OutputStream . StreamResult streamResult = new StreamResult(out);
write(node, streamResult, props);
|
void | writeElement(Element element, String fileName) Writes an element out to a file. File file = new File(fileName); file.delete(); DOMSource domSource = new DOMSource(element); FileOutputStream fos = null; try { fos = new FileOutputStream(file); StreamResult result = new StreamResult(fos); TransformerFactory transformerFactory = TransformerFactory.newInstance(); ... |
void | writeNodeSubtreeXMLString(final Node node, final Writer writer) write Node Subtree XML String try { final DOMSource domSource = new DOMSource(node); final StreamResult result = new StreamResult(writer); final TransformerFactory tf = TransformerFactory.newInstance(); final Transformer transformer = tf.newTransformer(); transformer.transform(domSource, result); } catch (TransformerException ex) { ex.printStackTrace(); ... |
String | writePropToString(Properties props) Convert Properties to string try { org.w3c.dom.Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); org.w3c.dom.Element conf = doc.createElement("configuration"); doc.appendChild(conf); conf.appendChild(doc.createTextNode("\n")); for (Enumeration e = props.keys(); e.hasMoreElements();) { String name = (String) e.nextElement(); Object object = props.get(name); ... |
void | writeResultToFile(final StreamResult result, final String path) save StreamResult to file given in path final String fileString = result.getWriter().toString(); try { final BufferedWriter out = new BufferedWriter(new FileWriter(path)); out.write(fileString); out.close(); } catch (final IOException e) { e.printStackTrace(); |
org.w3c.dom.Document | writeToFile(String xmlContent, String path) write To File System.out.println("This is the path " + path); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; try { builder = factory.newDocumentBuilder(); org.w3c.dom.Document doc = builder.parse(new InputSource(new StringReader(xmlContent))); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); ... |