You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "陳照東) <alex@erp.ncu.edu.tw>" <Alex> on 2001/03/21 05:02:24 UTC

encoding incorrect ????

hi Dear all: 

i creat a dom tree in the jsp and set encoding as UTF-8, 
then i check it and it represnt is correct display , 
but when i apply it to transforming , the encoding display just  wrong!!!  ,
i have setPropertiy ENCODING in UTF-8 ,
but it does'nt effect !!  
why?????

<%
Document doc= new DocumentImpl();
            Element root = doc.createElement("person");     // Create Root Element
            Element item = doc.createElement("name");       // Create element
            item.appendChild( doc.createTextNode("東") );
            root.appendChild( item );                       // atach element to Root element
            item = doc.createElement("age");                // Create another Element
            item.appendChild( doc.createTextNode("28" ) );       
            root.appendChild( item );                       
            item = doc.createElement("height");            
            item.appendChild( doc.createTextNode("1.80" ) );
            root.appendChild( item );                                 
           doc.appendChild( root );       
Node nd=doc;
OutputFormat    format  = new OutputFormat( doc );   //Serialize DOM
format.setEncoding("UTF-8");
format.setMethod("XML");
            StringWriter  stringOut = new StringWriter();        //Writer will be a String
            XMLSerializer    serial = new XMLSerializer( stringOut, format );
            serial.asDOMSerializer();                            // As a DOM Serializer

            serial.serialize( doc.getDocumentElement() );

             //Spit out DOM as a String
String testname="test.xsl";
String filename4=application.getRealPath(testname); 
Templates pss1=tsf.newTemplates(new StreamSource(new FileInputStream(filename4)));
     Transformer transformer1=pss1.newTransformer();
   StringWriter stringwriter1=new StringWriter();

transformer1.setOutputProperty("encoding","UTF-8");
     transformer1.transform(new DOMSource(nd),new StreamResult(stringwriter1));

%>
<%=stringOut.toString()%>     // display correct !!!!

<%=stringwriter1.toString()%>  //display just WRONG !!!


HELP ME!!!



IT DEP. Special Team-XML 
       Alex      
Tel:(03)4227151 ext:6024

alex@ERP.NCU.EDU.TW
=We Do Enterprise Services=