[jdom-interest] About encoding in jdom-b8

Gu Xueying (Shinnie Gu) Shinnie.Gu at iuniverse.com.cn
Mon Jul 22 19:13:53 PDT 2002


Hi,
I met some strange results when I use encoding in jdomb8.
Summary of the problem:
1. read the source xml. Just read the xml element text but found that 
    ’ — …...... are all turned into ASCII code 63.
2. encode the string which is read from the source xml with XMLOutputter.
    But found that all the code above are prefixed with ASCII code 194.
3. put the encoded string into pdf parser then output pdf. Found that they
have been 
    turned into the origin string again. 
But in step 2. when we output the string in a html the ASCII code 194 which
are not expected
appeared in the html. 
Any help is appreciated.

Here is the source code of TestEncode.java and the source xml.
*************************************************************************
import java.util.*;
import java.io.*;

import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.Element;
import org.jdom.Attribute;
import org.jdom.input.*;
import org.jdom.output.*;

public class TestEncode {

   
    public static void main(String[] args) {
        TestSend testSendMarketToolkitMessage1 = new TestSend();
        String messageStr=null;
        try{
			File templateFile = new File("testencode.xml");
			if(!templateFile.exists()){
			throw new Exception("Cannot find testencode.xml");
			}

           	// Using default dom adapter
			String domAdapterClass = null;
			//create DOM builder
			DOMBuilder builder = null;
			if (domAdapterClass == null) {
			builder = new DOMBuilder();
			} else {
			builder = new DOMBuilder(domAdapterClass);
			}	  
            
			//build the coverData DOM document from fi
			Document coverDataDoc = builder.build(templateFile);
	        String text = coverDataDoc.getRootElement().getTextTrim();
            
            
            FileOutputStream fos;
            PrintStream ps;
			//open the outputstream for the output file.
			fos =  new FileOutputStream("testencode1.txt");
			ps = new PrintStream(fos);
			ps.print(text);
			ps.close();
			
			//encode
            XMLOutputter outputter = new XMLOutputter();
	        ByteArrayOutputStream out = new ByteArrayOutputStream();
	        outputter.output(text,out);
	        text = out.toString();


    	    //open the outputstream for the output file.
			fos =  new FileOutputStream("testencode2.xml");
			ps = new PrintStream(fos);
			ps.print("<ROOT>"+text+"</ROOT>");
			ps.close();
        
			//build the coverData DOM document from fi
			coverDataDoc = builder.build(new
File("testencode2.xml"));
	        text = coverDataDoc.getRootElement().getTextTrim();
    	    //open the outputstream for the output file.
			fos =  new FileOutputStream("testencode2.txt");
			ps = new PrintStream(fos);
			ps.print(text);
			ps.close();            
            
        }catch(Exception e)
        {
            System.out.println(e.getMessage());
        }

    }
}
****************************************************************************
*******************************
<BLURB>&lt;p&gt;Julie O&#146;Connor&#8230;left the New York Police
Department trying to escape her past. Manny Scanlon left Miami law
enforcement running from his nightmares. As Sheriff&#146;s deputies in a
small rural Florida town they hope to leave their pasts behind.
&lt;/p&gt;&lt;p&gt;
	They are called upon to investigate the murder of a Federal
Inspector found in his car off the side of road, an apparent drive by
shooting.&lt;/p&gt;&lt;p&gt;
	As they probe deeper into his death they are drawn into a world of
greed, murder and political corruption that that reaches the highest
echelons of government and business.&lt;/p&gt;&lt;p&gt;
	Their investigation leads them deep into the Florida Everglades
where their discoveries uncover a catastrophic secret. A secret whose
consequence would change their way of life forever&#133;a secret that pits
them against the forces of evil driven by power and ambition. It is a tale
of greed, power, murder and retribution&#151;and one woman&#146;s search for
justice.&lt;/p&gt;
</BLURB>


Shinnie Gu
IUniverse(Shanghai)Co.,Ltd.
Tel:8621-58305001 Ext.8701





More information about the jdom-interest mailing list