我写了一个小程序利用sax解析xml,在解析英文时正常,但解析中文时报错。
not well-formed
代码如下:
     HttpDownloader httpDownloader = new HttpDownloader();
     InputStream inputstream=httpDownloader.getInputStream(urlStr);
     ArrayList<News> newstable = null;
          InputSource is = new InputSource(inputstream); 
     is.setEncoding("UTF-8"); 
         try {
     SAXParserFactory factory = SAXParserFactory.newInstance();
     SAXParser parser = factory.newSAXParser();
     XMLContentHandler XMLobj=new XMLContentHandler();
     parser.parse(inputstream, XMLobj);  
     newstable=XMLobj.getnewstable();
     datacls dbHelper = new datacls(this);
     }catch(Exception e)
     {
     e.printStackTrace();
     ShowToast("更新失败");
     }谢谢

解决方案 »

  1.   

    <?xml version="1.0" encoding="UTF-8"?>
    <newstable>
    <news>
    <oldid>6</oldid>
    <title>1title</title>
    <content>1content</content>
    </news>
    <news>
    <oldid>7</oldid>
    <title>2title</title>
    <content>2content</content>
    </news>
    <news>
    <oldid>8</oldid>
    <title>3title</title>
    <content>3content</content>
    </news>
    <news>
    <oldid>9</oldid>
    <title>4title</title>
    <content>4content</content>
    </news>
    <news>
    <oldid>10</oldid>
    <title>5title</title>
    <content>aaaaaa2这是中文测试</content>
    </news>
    </newstable>
      

  2.   

    http://blog.csdn.net/android_tutor/article/details/5890835
      

  3.   

    自己找到问题了。还是XML文件本身的问题。
    用记事本写xml文件时一定要记得将文件用utf-8保存一下就ok了。