Search in sources :

Example 1 with XMLSerializer

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;
}
Also used : XMLSerializer(org.apache.xml.serialize.XMLSerializer) OutputFormat(org.apache.xml.serialize.OutputFormat)

Example 2 with XMLSerializer

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);
}
Also used : XMLSerializer(org.apache.xml.serialize.XMLSerializer) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OutputFormat(org.apache.xml.serialize.OutputFormat) Document(org.w3c.dom.Document)

Example 3 with XMLSerializer

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);
}
Also used : InputSource(org.xml.sax.InputSource) XMLSerializer(org.apache.xml.serialize.XMLSerializer) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) OutputFormat(org.apache.xml.serialize.OutputFormat) Document(org.w3c.dom.Document)

Example 4 with XMLSerializer

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());
}
Also used : DOMSerializer(org.apache.xml.serialize.DOMSerializer) XMLSerializer(org.apache.xml.serialize.XMLSerializer) OutputFormat(org.apache.xml.serialize.OutputFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 5 with XMLSerializer

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();
}
Also used : XMLSerializer(org.apache.xml.serialize.XMLSerializer) FileOutputStream(java.io.FileOutputStream) OutputFormat(org.apache.xml.serialize.OutputFormat) PrintWriter(java.io.PrintWriter)

Aggregations

XMLSerializer (org.apache.xml.serialize.XMLSerializer)10 OutputFormat (org.apache.xml.serialize.OutputFormat)9 FileOutputStream (java.io.FileOutputStream)5 Document (org.w3c.dom.Document)4 File (java.io.File)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 Element (org.w3c.dom.Element)2 DatabaseSnapshotException (com.axway.ats.common.dbaccess.snapshot.DatabaseSnapshotException)1 TableDescription (com.axway.ats.common.dbaccess.snapshot.TableDescription)1 FileSystemSnapshotException (com.axway.ats.common.filesystem.snapshot.FileSystemSnapshotException)1 AtsConfigurationException (com.axway.ats.core.atsconfig.exceptions.AtsConfigurationException)1 ClassDoc (com.sun.javadoc.ClassDoc)1 MethodDoc (com.sun.javadoc.MethodDoc)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 StringReader (java.io.StringReader)1