Package org.apache.xml.serialize

Examples of org.apache.xml.serialize.OutputFormat


       
        StringWriter sw = new StringWriter();
       
        // write new XML instance
        try {
            OutputFormat format = new OutputFormat(instanceS);
            XMLSerializer output = new XMLSerializer(sw, format);
            output.serialize(instanceS);
        } catch (IOException e) {
            _logger.debug("IOException: "+e.toString());
        }
View Full Code Here


     * @return The element in String form.
     * @throws IOException If an error occurs while serializing
     */
    public static String elementToString(Element element) throws IOException {
        StringWriter writer = new StringWriter();
        OutputFormat format = new OutputFormat();
        format.setOmitXMLDeclaration(true);
        XMLSerializer serializer = new XMLSerializer(writer, format);
        serializer.serialize(element);
        return writer.toString();
    }
View Full Code Here

    catch (IOException e){
      logger.debug("IO file error: "+e.toString());
    }

    try {
      OutputFormat format = new OutputFormat(document);
      XMLSerializer output = new XMLSerializer(bw, format);
      output.serialize(document);
    }
    catch (IOException e) {
      logger.debug(e);
View Full Code Here

        source.setCharacterStream(stringReader);
        return source;
    }

    protected XMLSerializer createSerializer(Writer writer) {
        OutputFormat format = new OutputFormat();
        format.setOmitXMLDeclaration(true);
        format.setLineSeparator("\n");
        format.setPreserveSpace(true);
        XMLSerializer serializer = new XMLSerializer(format);
        serializer.setOutputCharStream(writer);
        return serializer;
    }
View Full Code Here

        int depth = -1;
        ExternalTransaction tx = database.newTransaction();
        tx.begin();
        try {
            StringWriter writer = new StringWriter();
            XMLSerializer serializer = new XMLSerializer( writer, new OutputFormat(type, encoding, indenting) );
            ContentHandler handler = serializer.asContentHandler();
            container.extractSAX( handler, null, depth );
            writer.flush();
            tx.commit();
            return writer.toString();
View Full Code Here

    StringWriter writer = null;
    String ret = null;

    try {
      writer = new StringWriter();
      OutputFormat format = new OutputFormat(doc);
      format.setLineWidth(80);
      format.setIndenting(true);
      format.setIndent(2);
      XMLSerializer serializer = new XMLSerializer(writer, format);
      serializer.serialize(doc);

      ret = writer.toString();
    } finally {
View Full Code Here

   * @return formattedXml
   */
  public static String format(String unformattedXml) {
    try {
      final Document document = parseXmlFile(unformattedXml);
      OutputFormat format = new OutputFormat(document);
      format.setLineWidth(65);
      format.setIndenting(true);
      format.setIndent(2);
      Writer out = new StringWriter();
      XMLSerializer serializer = new XMLSerializer(out, format);
      serializer.serialize(document);
      return out.toString();
    } catch (IOException e) {
View Full Code Here

        customBuilder.getModelProcessor().write(composite, writer);
       
        // Parse and write again to pretty format it
        DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document document = documentBuilder.parse(new ByteArrayInputStream(bos.toByteArray()));
        OutputFormat format = new OutputFormat();
        format.setIndenting(true);
        format.setIndent(2);
        XMLSerializer serializer = new XMLSerializer(System.out, format);
        System.out.println("-->Runtime SCDL model for composite " + composite.getName());
        serializer.serialize(document);
    }
View Full Code Here

          String extractFormat = params.get(ExtractingParams.EXTRACT_FORMAT, "xml");
          writer = new StringWriter();
          if (extractFormat.equals(TEXT_FORMAT)) {
            serializer = new TextSerializer();
            serializer.setOutputCharStream(writer);
            serializer.setOutputFormat(new OutputFormat("Text", "UTF-8", true));
          } else {
            serializer = new XMLSerializer(writer, new OutputFormat("XML", "UTF-8", true));
          }
          if (xpathExpr != null) {
            Matcher matcher =
                    PARSER.parse(xpathExpr);
            serializer.startDocument();//The MatchingContentHandler does not invoke startDocument.  See http://tika.markmail.org/message/kknu3hw7argwiqin
View Full Code Here

   * @return formattedXml
   */
  public static String format(String unformattedXml) {
    try {
      final Document document = parseXmlFile(unformattedXml);
      OutputFormat format = new OutputFormat(document);
      format.setLineWidth(65);
      format.setIndenting(true);
      format.setIndent(2);
      Writer out = new StringWriter();
      XMLSerializer serializer = new XMLSerializer(out, format);
      serializer.serialize(document);
      return out.toString();
    } catch (IOException e) {
View Full Code Here

TOP

Related Classes of org.apache.xml.serialize.OutputFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.