XmlPullParser is not working with InputStream

前端 未结 2 721
鱼传尺愫
鱼传尺愫 2021-01-06 02:01

I am using XmlPullParser for xml parsing in my android app but when I set input as InputStream it not works while I set input as Reader it starts working

Xm         


        
相关标签:
2条回答
  • 2021-01-06 02:06

    Got the answer for a similar problem from yano on this thread: XmlPullParser - unexpected token (android)

    You need to move from file from res/xml to assets and get the file with the code:

    InputStream in = this.getAssets().open("sample.xml");
    

    Apparently getRawResource() does not read the encoding properly and if you just dump the contents of the inputstream there are plenty of garbage characters.

    0 讨论(0)
  • 2021-01-06 02:11

    The same problem: passing InputStream directly works fine on Android 2.3.3 but doesn't work on 4.1. You can use xpp.setInput(new InputStreamReader(obj));

    0 讨论(0)
提交回复
热议问题