org.xml.sax.SAXParseException: Unexpected token while parsing XML

前端 未结 4 1322
北海茫月
北海茫月 2021-01-13 16:13

Update:- Seems like I have to give the URL which is returning me the xml. Here it is - URL


I am getting SAXParseException when parsing an xml.

相关标签:
4条回答
  • 2021-01-13 16:40

    I recommend abandoning the sax parser and using the Android officially supported XMLPullParser. Sax parser is not supported after Android Gingerbread (2.3.3)

    0 讨论(0)
  • 2021-01-13 16:49

    The problem was in the encoding. The following answer explains it properly -

    https://stackoverflow.com/a/2869127/1079901

    I just have to call this regex on the response string -

    response = response.replaceAll("[^\\x20-\\x7e]", "");
    

    Thanks to BalusC for such a perfect answer.

    0 讨论(0)
  • 2021-01-13 16:56


    If the XML contains Unicode characters such as arabic or Persian letters, StringReader would make an exception. In these cases, pass the InputStream straightly to the Document object

    0 讨论(0)
  • 2021-01-13 16:57

    I would recommend trying to incorporate some XSD validation in your program before you run it through your code.

    The following may help you in your efforts:

    • Online XSD Validator Tool: http://www.utilities-online.info/xsdvalidation/
    • Xerces for Android: https://code.google.com/p/xerces-for-android/
    0 讨论(0)
提交回复
热议问题