[jdom-interest] StringReader and Unicode char

alex alexdingdang at hotmail.com
Fri Apr 4 00:01:14 PST 2003


Dear ben

The following are the xml and java file,my problem still exists.........

exampleA.xml
<?xml version="1.0" encoding="UTF-16"?>

<bookList>

    <book>

        <name>方法</name>

        <author>333</author>

        <publishDate>2002-6-6</publishDate>

        <price>35.0</price>

    </book>

</bookList>
 
 
import org.jdom.*;
import org.jdom.output.*;
import org.jdom.input.*;
import java.io.*;
import java.net.*;
import org.xml.sax.*;
public class SaxParser  {
  public static void main(String[] argv) {

    SAXBuilder sb = new SAXBuilder();
    String tt= "";
      try{
        File file =new File("exampleA.xml");
        Reader rdr = new FileReader(file);
        long sz=file.length();
        char[] ch =new char[(int)sz];
        rdr.read(ch);
        rdr.close();
        tt=new String(ch);
        }

      catch(Exception e){
       e.printStackTrace();
      }
        System.out.println(tt);
        StringReader sr=new StringReader(tt);

        Document doc=null;
        try{
         doc = sb.build(sr);
        }
        catch(JDOMException e){
        e.printStackTrace() ;
        System.out.println(e.getMessage() );
        }
  }
}
  ----- Original Message ----- 
  From: Benjamin Kopic 
  To: alex 
  Sent: Tuesday, April 01, 2003 6:10 PM
  Subject: Re: [jdom-interest] StringReader and Unicode char


  alex, just off top  of my head, do you use 'UTF-16' or 'UTF-8' in your xml string? if nothing is specified, then jdom assumes that the encoding is 'UTF-8', which might be your problem.

  best regards

  ben



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20030404/3f124cbf/attachment.htm


More information about the jdom-interest mailing list