List of usage examples for org.dom4j.io XMLWriter XMLWriter
public XMLWriter(OutputStream out, OutputFormat format) throws UnsupportedEncodingException
From source file:com.liveneo.plat.web.action.MakeLicfile.java
public static void createXmlFile(String fileName, Document doc) { try {//w ww . j a v a 2 s. c o m File testfile = new File("fileName"); if (testfile.exists()) { testfile.delete(); } FileWriter fileWriter = new FileWriter(fileName); OutputFormat xmlFormat = OutputFormat.createPrettyPrint(); xmlFormat.setEncoding("UTF-8"); xmlFormat.setSuppressDeclaration(false); xmlFormat.setExpandEmptyElements(false); XMLWriter xmlWriter = new XMLWriter(fileWriter, xmlFormat); xmlWriter.write(doc); xmlWriter.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.love320.templateparser.label.impl.LabelBeanDaoImpl.java
License:Apache License
private boolean XMLWriter() { try {/*from ww w .j a v a 2s.com*/ OutputFormat format = OutputFormat.createPrettyPrint();//? format.setEncoding("UTF-8");//? XMLWriter output = new XMLWriter(new FileWriter(new File(configPath)), format);//? output.write(DOCROOT.getDocument());// output.close();// return true; } catch (IOException e) { logger.error("IOException", e); } return false; }
From source file:com.magicpwd._util.Jxml.java
License:Open Source License
public static void save(Document document, File file) throws IOException { // ?/*ww w. j ava 2 s . com*/ OutputFormat format = OutputFormat.createPrettyPrint(); // ?? // OutputFormat format = OutputFormat.createCompactFormat(); // XML? // format.setEncoding("GBK"); XMLWriter writer = new XMLWriter(new FileWriter(file), format); writer.write(document); writer.close(); }
From source file:com.marklogic.client.example.handle.DOM4JHandle.java
License:Apache License
@Override public void write(OutputStream out) throws IOException { Writer writer = new OutputStreamWriter(out, "UTF-8"); OutputFormat outputFormat = getOutputFormat(); if (outputFormat != null) { new XMLWriter(writer, outputFormat).write(content); } else {// w ww . jav a2 s.co m new XMLWriter(writer).write(content); } writer.flush(); }
From source file:com.ms.commons.test.treedb.Objects2XmlFileUtil.java
License:Open Source License
private static String prettyPrint(final String xml) { if (StringUtils.isBlank(xml)) { throw new RuntimeException("xml was null or blank in prettyPrint()"); }// w w w . j a va2 s. com final StringWriter sw; try { final OutputFormat format = OutputFormat.createPrettyPrint(); final org.dom4j.Document document = DocumentHelper.parseText(xml); sw = new StringWriter(); final XMLWriter writer = new XMLWriter(sw, format); writer.write(document); } catch (Exception e) { throw new RuntimeException("Error pretty printing xml:\n" + xml, e); } return sw.toString(); }
From source file:com.nokia.ant.Database.java
License:Open Source License
public void createXMLFile(File outputFile) { try {//from w w w .j av a 2 s . co m Document outDoc = createDOM(); OutputStream outStream = System.out; if (outputFile != null) { outStream = new FileOutputStream(outputFile); } XMLWriter out = new XMLWriter(outStream, OutputFormat.createPrettyPrint()); out.write(outDoc); } catch (Exception e) { throw new BuildException(e.getMessage()); } }
From source file:com.nokia.ant.ModelPropertiesParser.java
License:Open Source License
/** * Writes Document object as xml file//from w w w . jav a 2s .c o m */ private void writeXMLFile() { try { if (outputPath != null) { XMLWriter out = new XMLWriter(new FileOutputStream(outputPath), OutputFormat.createPrettyPrint()); out.write(doc); } } catch (FileNotFoundException e) { // We are Ignoring the errors as no need to fail the build. log.debug("Not able to write into XML Document " + e.getMessage()); } catch (UnsupportedEncodingException e) { // We are Ignoring the errors as no need to fail the build. log.debug("Not able to write into XML Document " + e.getMessage()); } catch (IOException e) { // We are Ignoring the errors as no need to fail the build. log.debug("Not able to write into XML Document " + e.getMessage()); } }
From source file:com.nokia.helium.core.ant.filters.PrettyPrintXmlFilter.java
License:Open Source License
/** * Filter the input string./*from ww w. j a v a 2s.c o m*/ * * @param string * the string to filter * @return the modified string */ public String filter(String token) { String output = token; XMLWriter writer = null; if (token.length() > 0) { try { Document doc = DocumentHelper.parseText(token); StringWriter out = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setIndentSize(4); writer = new XMLWriter(out, format); writer.write(doc); output = out.toString(); } catch (org.dom4j.DocumentException exc) { throw new BuildException(exc.getMessage(), exc); } catch (IOException exc) { throw new BuildException(exc.getMessage(), exc); } finally { try { if (writer != null) { writer.close(); } } catch (IOException exc) { throw new BuildException(exc.getMessage(), exc); } } } return output; }
From source file:com.nokia.helium.diamonds.XMLMerger.java
License:Open Source License
/** * Write the XML content back the file./*from ww w.ja v a2 s . co m*/ * @throws XMLMergerException */ protected void write() throws XMLMergerException { try { FileOutputStream fos = new FileOutputStream(outputFile); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(fos, format); writer.write(doc); writer.flush(); } catch (FileNotFoundException e) { throw new XMLMergerException(e.getMessage()); } catch (UnsupportedEncodingException e) { throw new XMLMergerException(e.getMessage()); } catch (IOException e) { throw new XMLMergerException(e.getMessage()); } }
From source file:com.nokia.helium.environment.EnvironmentXMLWriter.java
License:Open Source License
/** * Writes an environment definition in XML to output. * @param environment Enviroment definition. * @throws IOException If I/O error occurs. *//*from w w w .jav a2 s . c o m*/ public void write(Environment environment) throws IOException { doc = DocumentFactory.getInstance().createDocument(); doc.addElement("environment"); List<Executable> executables = environment.getExecutables(); for (Iterator<Executable> iterator = executables.iterator(); iterator.hasNext();) { Executable executable = (Executable) iterator.next(); write(executable); } XMLWriter writer = new XMLWriter(out, OutputFormat.createPrettyPrint()); writer.write(doc); writer.close(); }