Package org.apache.xml.serialize

Examples of org.apache.xml.serialize.OutputFormat


   * Convert an XML document to a latin-1 string
   */
  public static String serializeXML(Document document) throws GUIException {
    try {
      StringWriter stringWriter = new StringWriter();
      OutputFormat format = new OutputFormat("XML", "ISO-8859-1", true);
      format.setLineWidth(0);
      XMLSerializer serializer = new XMLSerializer(stringWriter, format);
      serializer.asDOMSerializer().serialize(document);
      /* We don't want the newline character at the end */
      String string = stringWriter.toString();
      return string.substring(0, string.length() - 1);
View Full Code Here


        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);
            }
            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) {
View Full Code Here

        StringWriter tXMLWriter = new StringWriter();

        try
        {
            // a serializer
            OutputFormat outputFormat = new OutputFormat( mXMLDocument, null, true );   //@XERCES
            outputFormat.setEncoding(mEncoding);                                        //@XERCES
            XMLSerializer ser = new XMLSerializer( tXMLWriter, outputFormat );          //@XERCES
            ser.serialize( mXMLDocument );                                              //@XERCES
            return tXMLWriter.toString();
        }
        catch( IOException e )
View Full Code Here

        StringWriter tXMLWriter = new StringWriter();

        try
        {
            // a serializer
            OutputFormat outputFormat = new OutputFormat( mXMLDocument, null, true );   //@XERCES
            outputFormat.setEncoding(mEncoding);                                        //@XERCES
            XMLSerializer ser = new XMLSerializer( tXMLWriter, outputFormat );          //@XERCES
            ser.serialize( mXMLDocument );                                              //@XERCES
        }
        catch( IOException e )
        {
View Full Code Here

    factory.setExpandEntityReferences(true);
    return factory.newDocumentBuilder().parse(new InputSource(source));
  }
 
  public static void write(Document doc, Writer writer) throws IOException {
    OutputFormat format = new OutputFormat();
    format.setIndenting(INDENTING);
    XMLSerializer serializer = new XMLSerializer(format);
    serializer.setNamespaces(true);
    serializer.setOutputCharStream(writer);
    serializer.serialize(doc);
  }
View Full Code Here

    serializer.setOutputCharStream(writer);
    serializer.serialize(doc);
  }

  public static void write(Element elem, Writer writer) throws IOException {
    OutputFormat format = new OutputFormat();
    format.setIndenting(INDENTING);
    XMLSerializer serializer = new XMLSerializer(format);
    serializer.setNamespaces(true);
    serializer.setOutputCharStream(writer);
    serializer.serialize(elem);
  }
View Full Code Here

    String jobName = "";   
    try{
      Element updatedJob = updatedJobDoc.getDocumentElement();
      jobName = updatedJob.getAttribute("name");     
      StringWriter out = new StringWriter();
      OutputFormat format = new OutputFormat(updatedJobDoc);
      format.setEncoding("ISO-8859-1");
      format.setIndenting(true);
      format.setIndent(2);
          XMLSerializer serializer = new XMLSerializer(out, format);
          serializer.serialize(updatedJobDoc);
          logger.debug3("submitting job... ");
          logger.debug9(out.toString());
          String answer = spooler.execute_xml(out.toString());
View Full Code Here

      String fileName = normalizeJobName(jobName);
      updatedJob.removeAttribute("name");
      jobFile = new File(schedulerCronConfigurationDir, fileName+".job.xml");
      OutputStream fout = new FileOutputStream(jobFile,false);         
          OutputStreamWriter out = new OutputStreamWriter(fout, "UTF-8");
      OutputFormat format = new OutputFormat(updatedJobDoc);
      format.setEncoding("UTF-8");
      format.setIndenting(true);
      format.setIndent(2);
          XMLSerializer serializer = new XMLSerializer(out, format);
          logger.debug3("Writing file "+jobFile.getAbsolutePath());
          serializer.serialize(updatedJobDoc);
          out.close();
    } catch (Exception e){
View Full Code Here

    try{
      Document configurationDocument = cronFile2SchedulerXML(cronFile, new HashMap());
      logger.debug("writing "+schedulerXML.getAbsolutePath());
      OutputStream fout = new FileOutputStream(schedulerXML,false);         
          OutputStreamWriter out = new OutputStreamWriter(fout, "UTF-8");
      OutputFormat format = new OutputFormat(configurationDocument);
      format.setEncoding("UTF-8");
      format.setIndenting(true);
      format.setIndent(2);
          XMLSerializer serializer = new XMLSerializer(out, format);
          serializer.serialize(configurationDocument);
          out.close();
    } catch (Exception e){
      throw new Exception ("Error writing Job Scheduler configuration file: "+e,e);
View Full Code Here

        // can later be deleted (keep only else branch)
        usedNewRunTime = false;
        Document runTimeDocument = docBuilder.newDocument();
        runTimeDocument.appendChild(runTimeDocument.importNode(runTimeElement, true));
        StringWriter out = new StringWriter();
        OutputFormat format = new OutputFormat(runTimeDocument);   
        format.setIndenting(true);
        format.setIndent(2);
        format.setOmitXMLDeclaration(true);
            XMLSerializer serializer = new XMLSerializer(out, format);
            serializer.serialize(runTimeDocument);
            Comment runTimeComment = jobDoc.createComment("This run_time is currently not supported:\n"+out.toString());
            jobElement.appendChild(runTimeComment);
      } else{
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.