Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ksoap2 xmlPullParserException unterminated entity ref

I have a user email me yesterday that he is having a problem with my application so i started debugging with him and had him sent me the log of the phone and he is getting a XmlPullParserError when he makes a call to the server

E/Message Exchange::CallWebService(6426): Exception: org.xmlpull.v1.XmlPullParserException: unterminated entity ref (position:TEXT �������`I�...@1:18 in java.io.InputStreamReader@406c8808) 05-31 12:33:25.573 
W/System.err(6426): org.xmlpull.v1.XmlPullParserException: unterminated entity ref (position:TEXT �������`I�...@1:18 in java.io.InputStreamReader@406c8808) 05-31-12:33:25.573 
W/System.err(6426):     at org.kxml2.io.KXmlParser.exception(KXmlParser.java:273)05-31 12:33:25.573 
W/System.err(6426):     at org.kxml2.io.KXmlParser.error(KXmlParser.java:269)05-31-12:33:25.573 
W/System.err(6426):     at org.kxml2.io.KXmlParser.pushEntity(KXmlParser.java:781)05-31 12:33:25.573 
W/System.err(6426):     at org.kxml2.io.KXmlParser.pushText(KXmlParser.java:849)05-31 12:33:25.573 
W/System.err(6426):     at org.kxml2.io.KXmlParser.nextImpl(KXmlParser.java:354)05-31 12:33:25.573 
W/System.err(6426):     at org.kxml2.io.KXmlParser.next(KXmlParser.java:1378)05-31 12:33:25.573 
W/System.err(6426):     at org.kxml2.io.KXmlParser.nextTag(KXmlParser.java:1408)05-31 12:33:25.573 
W/System.err(6426):     at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:126)05-31 12:33:25.573 
W/System.err(6426):     at org.ksoap2.transport.Transport.parseResponse(Transport.java:100)05-31 12:33:25.573 
W/System.err(6426):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:195)05-31 12:33:25.573 
W/System.err(6426):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)05-31 12:33:25.573 
W/System.err(6426):     at ecm2.android.MessageExchange$1.run(MessageExchange.java:96)05-31 12:33:25.573 
W/System.err(6426):     at java.lang.Thread.run(Thread.java:1019)05-31 12:33:27.928 

this is the line it always fails at

trans.call(SOAP_ACTION, soapEnvelope);

that makes the call to the server and it just throws an error. I have the same exact phone this person has and I had him running the exact version I am running, I had not problems calling the server but he still had a problem.

I had him uninstall and reinstall several times so I dont know what would cause this on his phone and not mine?

this is how i create the XML

private static String CreateCallXML(String sDeviceID, String sEMailAddress, String sVersion) {
    Logging logger = new Logging();
    XmlSerializer serializer = Xml.newSerializer();
    StringWriter writer = new StringWriter();
    try {
        serializer.setOutput(writer);
        serializer.startDocument("UTF-8", true);
        serializer.startTag("", "PostData");
        serializer.startTag("", "RetrieveMsg");
        serializer.attribute("", "ver", sVersion);
        serializer.attribute("", "DevID", sDeviceID);
        serializer.attribute("", "eMailAddress", sEMailAddress);
        logger.append("D", className, "CreateCallXML", "LastIncMsgID:" + Settings.LastIncMsgID);
        logger.append("D", className, "CreateCallXML", "LastDLMsgID: " + Settings.LastDLMsgID);
        serializer.attribute("", "LastIncMsgID", "" + Settings.LastIncMsgID);
        serializer.attribute("", "LastDLMsgID", "" + Settings.LastDLMsgID);
        serializer.endTag("", "RetrieveMsg");
        serializer.endTag("", "PostData");
        serializer.endDocument();
        return writer.toString();
    } catch (Exception e) {
        return null;
    }
}

Update 2:

after going through the code it appears that the users email address is the problem an example of the users email address is [email protected] if I use that it throws the exception when it hits the line to make the call to the server. If I change one letter in the email address it executes the call fine.

is this a ksoap problem? and how can I get around this as i cannot tell him to change his email address?

like image 911
tyczj Avatar asked Nov 30 '22 05:11

tyczj


2 Answers

Unterminated entity this error occurs when

1... Error in response string may be some entity are not closed.

<root>
    <a> first </a>
    <b>second             <----- </b> missing here
</roor>

2... You are getting some xml character in xml file

 like      & { } � ...

you need to replace all & with & amp; see this answer

...
String str = writer.toString();
str = str.replaceAll("&","&amp;");
str = str.replaceAll("?","&#63;");
return str;
like image 193
MAC Avatar answered Dec 05 '22 00:12

MAC


I was having the same problem on an Android 2.2 device and found that ksoap2 2.6.5 isn't compatible with Android 2.2. Well I think that's the problem, all I know is it throws these errors. I downgraded my ksoap2 to 2.4 and it started working again.

like image 34
Tim T Avatar answered Dec 05 '22 01:12

Tim T