0

I'm parsing this XML Document, but getting the :

org.xml.sax.SAXParseException: Unexpected token (position:TEXT Parameter not sp...@1:# in java.io.InputStreamReader@4124af00) 

I have tried This Link, This Link as well but didn't got any solution This is my code where I convert String Data which got from HttpResponse, to Document and getting Exception:

protected Document convertWordDefinationToDocument(Context context,
        String defSource) {
    Document destDocument = null;

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = null;

    try {
        documentBuilder = factory.newDocumentBuilder();
        destDocument = documentBuilder.parse(new ByteArrayInputStream(defSource.getBytes("UTF-8")));// This is line where Exception occurs 
        return destDocument;
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
        return null;
    } catch (SAXException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }catch (Exception e) {
        return null;
    }
}

How can I solve that please help me...

Community
  • 1
  • 1
  • I have a repo at https://github.com/arshadalisoomro/AonawareDictServiceSDK, use this, see if this helps you. – Arshad Ali Mar 02 '14 at 18:37

1 Answers1

0

I pasted your xml into an xml validator and one other and received errors. The errors were caused by the & characters since they are specially parsed by xml parsers. The ampersands in the text of some of the Definitinitons need to be replaced with xml entities & or removed. That is probably what is killing you're parsing. It would probably help to validate the xml that you are receiving.

Hope that helps.

dudebrobro
  • 1,287
  • 10
  • 17
  • I think that would not kill the parsing because I have developed AonawareDictServiceSDK, at https://github.com/arshadalisoomro/AonawareDictServiceSDK, even it is in initial stage, but I works like charm. – Arshad Ali Mar 02 '14 at 18:42
  • Ok. My comment and suggestion is simply to check the validation on the xml that the poster tried to parse ... based on the xml provided in the question and what I saw from the from trying to validate the xml that is what seemed like it might have caused the exception that the parser threw. If using your SDK fixes the problem that's awesome! Whatever gets the problem solved. – dudebrobro Mar 02 '14 at 18:54
  • Yep our main goal is to solve the problem, what ever is the way of solution that does not matter at all, thanks a lot – Arshad Ali Mar 02 '14 at 18:58