简体   繁体   English

Android SAXParser格式错误的XMl错误

[英]Android SAXParser Malformed XMl error

I have a server component which uses SAXParser (javax.xml.parsers.SAXParserFactory) to parse an XML. 我有一个服务器组件,它使用SAXParser(javax.xml.parsers.SAXParserFactory)来解析XML。 I am reusing this library in my phonegap app for android. 我在我的phonegap应用程序中重用这个库来安卓android。 The problem is that when I use the library to communicate to the server and parse the response from the server, it fails with - Malformed XML - exception. 问题是,当我使用库与服务器进行通信并解析来自服务器的响应时,它会以 - 格式错误的XML - 异常失败。 However, if I use the same library from normal Java program, the response from the server is processed fine by the parser and there is no error. 但是,如果我使用普通Java程序中的相同库,则解析器会很好地处理来自服务器的响应,并且没有错误。 I compared the XML payloads in both android and normal javacase and they are exactly the same. 我比较了android和普通javacase中的XML有效负载,它们完全相同。 I know that this is a very vague and strange question with very little to go on but I am out of ideas. 我知道这是一个非常模糊和奇怪的问题,很少继续下去,但我没有想法。 Any ideas or hints would be helpful. 任何想法或提示都会有所帮助。

Is there a DTD or namespace in that XML? 该XML中是否有DTD或命名空间? It may be possible that the android app has a problem with those and fail to parse because of that. Android应用程序可能有问题,因此无法解析。 (Is there an exact error message?) (是否有确切的错误消息?)

You may check what are the differences between the parsers by checking 您可以通过检查来检查解析器之间的差异

There might be a difference. 可能会有所不同。 If there is, use SAXParserFactory#setNamespaceAware() and SAXParserFactory#setValidating() to set the same values. 如果有,请使用SAXParserFactory#setNamespaceAware()SAXParserFactory#setValidating()来设置相同的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM