use of org.apache.xml.serialize.OutputFormat in project vcell by virtualcell.
the class DOMUtil method serialize.
public static void serialize(Document document, OutputStream out) throws IOException {
OutputFormat format = new OutputFormat();
XMLSerializer serializer = new XMLSerializer(out, format);
DOMSerializer domSerializer = serializer.asDOMSerializer();
domSerializer.serialize(document);
}
use of org.apache.xml.serialize.OutputFormat in project mondrian by pentaho.
the class XmlUtility method save.
public static void save(Writer writer, Document document) throws IOException {
OutputFormat outputFormat = new OutputFormat(document);
outputFormat.setIndenting(true);
outputFormat.setLineWidth(Integer.MAX_VALUE);
outputFormat.setLineSeparator(Util.nl);
try {
XMLSerializer serializer = new XMLSerializer(writer, outputFormat);
serializer.serialize(document);
} finally {
if (writer != null) {
writer.close();
}
}
}
use of org.apache.xml.serialize.OutputFormat in project Lucee by lucee.
the class StorageUtil method store.
/**
* store loaded data to xml file
* @param doc
* @param res
* @throws IOException
*/
public void store(Document doc, Resource res) throws IOException {
OutputFormat format = new OutputFormat(doc, null, true);
format.setLineSeparator("\r\n");
format.setLineWidth(72);
OutputStream os = null;
try {
XMLSerializer serializer = new XMLSerializer(os = res.getOutputStream(), format);
serializer.serialize(doc.getDocumentElement());
} finally {
IOUtil.closeEL(os);
}
}
use of org.apache.xml.serialize.OutputFormat in project Gemma by PavlidisLab.
the class AbstractGemmaEndpoint method writeReport.
/**
* This method should/can only be used when the wrapper is manually built in the specific endpoints (ie. not using
* the buildWrapper() in AbstractGemmaEndpoint).
*
* @param responseWrapper - Manually built wrapper
* @param document document
* @param filename - no xml extension is required
*/
protected void writeReport(Element responseWrapper, Document document, String filename) {
String fullFileName = filename + ".xml";
String path = HOME_DIR + File.separatorChar + "dataFiles" + File.separatorChar + "xml" + File.separatorChar;
try {
File file = new File(path, fullFileName);
if (!file.exists()) {
// in case of the subdirs doesn't exisit.
new File(path).mkdirs();
try (FileOutputStream out = new FileOutputStream(path + fullFileName)) {
OutputFormat format = new OutputFormat(document);
format.setIndenting(true);
// to generate a file output use fileoutputstream
/*
* "It is recommended that new applications use the DOM Level 3 LSSerializer or JAXP's
* Transformation API for XML (TrAX) for serializing XML"
*/
XMLSerializer serializer = new XMLSerializer(out, null);
serializer.serialize(responseWrapper);
}
AbstractGemmaEndpoint.log.info("A report with the filename, " + fullFileName + ", has been created in path, " + path);
} else
AbstractGemmaEndpoint.log.info("A report with the filename, " + fullFileName + ", already exists. A new report was not created.");
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.apache.xml.serialize.OutputFormat in project mondrian by pentaho.
the class XmlUtil method toString.
/**
* Convert a Node to a String.
*/
public static String toString(Node node, boolean prettyPrint) {
if (node == null) {
return null;
}
try {
Document doc = node.getOwnerDocument();
OutputFormat format;
if (doc != null) {
format = new OutputFormat(doc, null, prettyPrint);
} else {
format = new OutputFormat("xml", null, prettyPrint);
// don't wrap lines
format.setLineWidth(0);
}
if (prettyPrint) {
format.setLineSeparator(LINE_SEP);
} else {
format.setLineSeparator("");
}
StringWriter writer = new StringWriter(1000);
XMLSerializer serial = new XMLSerializer(writer, format);
serial.asDOMSerializer();
if (node instanceof Document) {
serial.serialize((Document) node);
} else if (node instanceof Element) {
format.setOmitXMLDeclaration(true);
serial.serialize((Element) node);
} else if (node instanceof DocumentFragment) {
format.setOmitXMLDeclaration(true);
serial.serialize((DocumentFragment) node);
} else if (node instanceof Text) {
Text text = (Text) node;
return text.getData();
} else if (node instanceof Attr) {
Attr attr = (Attr) node;
String name = attr.getName();
String value = attr.getValue();
writer.write(name);
writer.write("=\"");
writer.write(value);
writer.write("\"");
if (prettyPrint) {
writer.write(LINE_SEP);
}
} else {
writer.write("node class = " + node.getClass().getName());
if (prettyPrint) {
writer.write(LINE_SEP);
} else {
writer.write(' ');
}
writer.write("XmlUtil.toString: fix me: ");
writer.write(node.toString());
if (prettyPrint) {
writer.write(LINE_SEP);
}
}
return writer.toString();
} catch (Exception ex) {
// ignore
return null;
}
}
Aggregations