DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=27353>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=27353

Indenting doesn't work well

           Summary: Indenting doesn't work well
           Product: XalanJ2
           Version: 2.5
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: org.apache.xml.serializer
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


When in.xml is printed as indenting is true and indent is 2, 
expected output is expected.xml. But I got actual.xml.

===== in.xml =====
<?xml version="1.0"?>
<a><b>b</b>
<c>c</c>
</a>
===================

===== expected.xml =====
<?xml version="1.0"?>
<a>
  <b>b</b>
  <c>c</c>
</a>
=========================

===== actual.xml =====
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<a>
  <b>b</b>
<c>c</c>     <==== indenting not correct
</a>
======================

The test code is below : 

===== PrintXalan.java =====
import java.io.*;
import java.util.*;

import javax.xml.parsers.*;

import org.w3c.dom.*;
import org.xml.sax.*;

import org.apache.xml.serializer.*;

public class PrintXalan {

        public static void main (String[] args) throws Exception {
                String inputPath = "in.xml";
                String outputPath = "outXalan.xml";

                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document doc = builder.parse(new InputSource(new 
FileInputStream(inputPath)));

                OutputStream out = null;
                try {
                        out = new FileOutputStream(outputPath);
                        print(out, doc, "UTF-8", true, 2);
                        out.flush();
                } finally {
                        if (out != null) out.close();
                }
        }

        public static void print(OutputStream out,
                                                                                       
                  Document doc,
                                                                                       
                  String encoding,
                                                                                       
                  boolean indenting,
                                                                                       
                  int indent) throws Exception {
                Properties outputFormat =
                        OutputPropertiesFactory.getDefaultMethodProperties(Method.XML);
                outputFormat.setProperty(OutputPropertiesFactory.S_KEY_INDENT_AMOUNT,
                                                                                       
                          String.valueOf(indent));
                ToStream serializer = new ToXMLStream();
                serializer.setOutputFormat(outputFormat);
                
                serializer.setWriter(new OutputStreamWriter(out, encoding));
                serializer.setEncoding(encoding);
                serializer.setIndent(indenting);
                
                serializer.serialize(doc);
        }
}
===========================

Reply via email to