正确终止 SaxParser 的流,避免“意外的文件结束”例外
我遇到了与此处引用的问题相同的问题安卓。
给出的解决方案是使用 URI 而不是输入流。
我相信您可以按照 API 指示使用 inputStream,但显然流有问题,导致解析方法引发异常。我可以确认所有数据都进入流中,并且 SAXParseException 指示所有数据都进入 parse 方法,因为我可以使用返回 -1 的 getColumnNumber 方法(指示整个流已被读取)。但看起来解析方法并没有承认这是流的结尾,因此引发了“意外的文件结尾”(?)
有人可以建议如何使用输入流而不是 URI 作为解析方法的输入吗?
I am having the same problem to the one quoted here on Android.
The solution given was to use a URI rather than the inputstream.
I believe that you can use an inputStream as the API indicates but obviously there is something wrong with the stream that is raising exceptions with the parse method. I can confirm all the data is going into the stream, and the SAXParseException indicates that all the data is going to the parse method as I can use getColumnNumber method which returns -1, (indicating the entire stream has been read). But it looks like the parse method is not acknowledging this as the end of the stream, thus raising the "Unexpected end of file" (?)
Can someone please advise how to use an inputstream rather than the URI as input to the parse method ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了这个问题,但原因是我接受了错误的编码格式的输入流。确保首先将其放入正确的编码中(可能通过将其作为 byte[] 读取并使用 String(byte[], String) 构造函数),然后尝试将其通过 SAX 解析器。
如果你想在 Android 中解析 XML,也许你最好使用 Android 中的简单库。
I had this problem but the cause was that I was accepting the inputstream in the wrong encoding format. Make sure that you put it in the right encoding first (maybe by reading it in as a byte[] and using the String(byte[], String) constructor) and then try and put it through the SAX parser.
And if you want to parse XML in Android maybe you would be better off using the Simple library in Android.