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=7029>.
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=7029

Encoding problem in CDATA

           Summary: Encoding problem in CDATA
           Product: Xerces2-J
           Version: 2.0.0
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Serialization
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


Run the following code (the output files should be the same, but are different):
import org.w3c.dom.*;
import java.io.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.apache.xml.serialize.*;

public class Test
{
        public static void main(String[] args)
        {
                try
                {
                        // Build the empty Document
                        DocumentBuilderFactory 
fac=DocumentBuilderFactory.newInstance();
                        DocumentBuilder builder=fac.newDocumentBuilder();
                        Document doc=builder.newDocument();
                        
                        // Append root and CDATA with the problematic letters
                        Element root=doc.createElement("root");
                        doc.appendChild(root);
                        root.appendChild(doc.createCDATASection("\u0105
\u015b\u017a\u0104\u015a\u0179"));
                        
                        // Write the XML file (correct output)
                        File output1=new File("output1.xml");
                        XMLSerializer serializer=new XMLSerializer(new 
FileWriter(output1), new OutputFormat("XML", "ISO-8859-2", false));
                        serializer.serialize(doc);
                        
                        // Parse the file again (here is a problem)
                        doc=builder.parse(output1);
                        
                        // Write the characters to System.out (incorrect output)
                        System.out.println(doc.getElementsByTagName("root").item
(0).getFirstChild().getNodeValue());
                        
                        // Write the XML file (incorrect output)
                        File output2=new File("output2.xml");
                        serializer=new XMLSerializer(new FileWriter(output2), 
new OutputFormat("XML", "ISO-8859-2", false));
                        serializer.serialize(doc);
                }
                catch (ParserConfigurationException exp)
                {
                        System.out.println("Parser configuration -
 "+exp.getMessage());
                }
                catch (IOException exp)
                {
                        System.out.println("IOException - "+exp.getMessage());
                }
                catch (SAXException exp)
                {
                        System.out.println("SAXException - "+exp.getMessage());
                }
        }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to