use of org.apache.xml.serialize.XMLSerializer in project jersey by jersey.
the class ResourceDoclet method getXMLSerializer.
private static XMLSerializer getXMLSerializer(final OutputStream os, final String[] cdataElements) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
// configure an OutputFormat to handle CDATA
final OutputFormat of = new OutputFormat();
// specify which of your elements you want to be handled as CDATA.
// The use of the '^' between the namespaceURI and the localname
// seems to be an implementation detail of the xerces code.
// When processing xml that doesn't use namespaces, simply omit the
// namespace prefix as shown in the third CDataElement below.
of.setCDataElements(cdataElements);
// set any other options you'd like
of.setPreserveSpace(true);
of.setIndenting(true);
// create the serializer
final XMLSerializer serializer = new XMLSerializer(of);
serializer.setOutputByteStream(os);
return serializer;
}
use of org.apache.xml.serialize.XMLSerializer in project opennms by OpenNMS.
the class Mib2Events method prettyPrintXML.
public static void prettyPrintXML(InputStream docStream, OutputStream out) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(docStream);
OutputFormat fmt = new OutputFormat(doc);
fmt.setOmitXMLDeclaration(true);
fmt.setLineWidth(72);
fmt.setIndenting(true);
fmt.setIndent(2);
XMLSerializer ser = new XMLSerializer(out, fmt);
ser.serialize(doc);
}
use of org.apache.xml.serialize.XMLSerializer in project opennms by OpenNMS.
the class SpectrumTrapImporter method prettyPrintXML.
private void prettyPrintXML(String inDoc) throws IOException, SAXException, ParserConfigurationException {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource inSrc = new InputSource(new StringReader(inDoc));
Document outDoc = builder.parse(inSrc);
OutputFormat fmt = new OutputFormat(outDoc);
fmt.setLineWidth(72);
fmt.setIndenting(true);
fmt.setIndent(2);
XMLSerializer ser = new XMLSerializer(m_outputWriter, fmt);
ser.serialize(outDoc);
}
use of org.apache.xml.serialize.XMLSerializer in project OpenAM by OpenRock.
the class AMEncryptionProvider method toString.
// converts the element to a string.
private String toString(Element doc) {
OutputFormat of = new OutputFormat();
of.setIndenting(true);
of.setMethod(Method.XML);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DOMSerializer serializer = new XMLSerializer(baos, of);
try {
serializer.serialize(doc);
} catch (IOException ioe) {
ioe.printStackTrace();
}
return (baos.toString());
}
use of org.apache.xml.serialize.XMLSerializer in project ACS by ACS-Community.
the class EbeDocument method saveXmlDocument.
/** Save the DOM document into the name path
* @param docu The DOM document
* @param name the filename path*/
private void saveXmlDocument(Document docu, String name) throws FileNotFoundException, java.io.IOException {
OutputFormat outFormat = new OutputFormat(Method.XML, null, true);
outFormat.setEncoding("UTF-8");
outFormat.setVersion("1.0");
FileOutputStream out = new FileOutputStream(name);
XMLSerializer xmlSerializer = new XMLSerializer(new PrintWriter(out), outFormat);
xmlSerializer.serialize(docu);
out.close();
}
Aggregations