All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nepxion.discovery.plugin.configcenter.parser.xml.dom4j.Dom4JWriter Maven / Gradle / Ivy

There is a newer version: 6.22.0
Show newest version
package com.nepxion.discovery.plugin.configcenter.parser.xml.dom4j;

/**
 * 

Title: Nepxion Discovery

*

Description: Nepxion Discovery

*

Copyright: Copyright (c) 2017-2050

*

Company: Nepxion

* @author Haojun Ren * @version 1.0 */ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; public class Dom4JWriter { public static Document createDocument() { return DocumentHelper.createDocument(); } public static String getText(Document document) throws IOException, UnsupportedEncodingException { return getText(document, Dom4JConstant.ENCODING_UTF_8); } public static String getText(Document document, String charset) throws IOException, UnsupportedEncodingException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputFormat outputFormat = new OutputFormat(" ", true, charset); try { XMLWriter writer = new XMLWriter(baos, outputFormat); writer.write(document); baos.flush(); } catch (UnsupportedEncodingException e) { throw e; } catch (IOException e) { throw e; } finally { if (baos != null) { baos.close(); } } return baos.toString(charset); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy