Когда я анализирую следующий XML и сохраняю его в HashMap, сообщение обрезается после ( ') этого символа.
Пример.Сообщение: «Эй, амар! Что случилось?».это обрезалось вот так.
- message = (3577): Эй, Амар!Что
- message = (3577): '
- message = (3577): s up?
Последний вывод: message = "s up? "
Итак, как решить эту проблему?
HashMap для хранения XML DATA:
public static HashMap<String,String> message_map1 = new HashMap<String,String>();
public static HashMap<String,String> message_map2 = new HashMap<String,String>();
public static HashMap<String,String> message_map3 = new HashMap<String,String>();
XML:
<statuses type="array">
<status>
<messageinfo>
<messageid>485</messageid>
<userid>58</userid>
**<message>Hey amar! What's up?</message>**
</messageinfo>
<messageinfo>
<messageid>486</messageid>
<userid>58</userid>
**<message>Hey What's up?</message>**
</messageinfo>
<messageinfo>
<messageid>485</messageid>
<userid>58</userid>
**<message>What's up?</message>**
</messageinfo>
</status>
</statuses>
код:
package com.xmldataparser;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import android.util.Log;
public class Message_XHandler extends DefaultHandler
{
boolean in_porf_msg_statuses;
boolean in_prof_msg_status;
boolean in_prof_msg_messageinfo;
boolean in_prof_msg_messageid;
boolean in_prof_msg_userid;
boolean in_prof_msg_message;
int i=0;
public String key = "";
public String value = "";
XMLData xml_message;
@Override
public void startDocument() throws SAXException
{
super.startDocument();
xml_message = new XMLData();
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException
{
super.startElement(uri, localName, qName, attributes);
if(localName.equalsIgnoreCase("statuses"))
{
in_porf_msg_statuses= true;
}
else if(localName.equalsIgnoreCase("status"))
{
in_prof_msg_status = true;
}
else if(localName.equalsIgnoreCase("messageinfo"))
{
in_prof_msg_messageinfo = true;
i++;
}
else if(localName.equalsIgnoreCase("messageid"))
{
in_prof_msg_messageid = true;
}
else if(localName.equalsIgnoreCase("userid"))
{
in_prof_msg_userid = true;
}
else if(localName.equalsIgnoreCase("message"))
{
in_prof_msg_message = true;
}
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException
{
super.characters(ch, start, length);
String chars = new String(ch,start,length);
chars = chars.trim();
else if(in_prof_msg_messageid)
{
if(i==1)
{
xml_message.message_map1.put("messageid", chars);
}
else if(i==2)
{
xml_message.message_map2.put("messageid", chars);
}
else if(i==3)
{
xml_message.message_map3.put("messageid", chars);
}
Log.v("messageid = ", chars);
}
else if(in_prof_msg_userid)
{
if(i==1)
{
xml_message.message_map1.put("userid", chars);
}
else if(i==2)
{
xml_message.message_map2.put("userid", chars);
}
else if(i==3)
{
xml_message.message_map3.put("userid", chars);
}
Log.v("userid = ", chars);
}
else if(in_prof_msg_message)
{
if(i==1)
{
xml_message.message_map1.put("message", chars);
}
else if(i==2)
{
xml_message.message_map2.put("message", chars);
}
else if(i==3)
{
xml_message.message_map3.put("message", chars);
}
Log.v("message = ", chars);
}
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException
{
super.endElement(uri, localName, qName);
if(localName.equalsIgnoreCase("statuses"))
{
in_porf_msg_statuses = false;
}
else if(localName.equalsIgnoreCase("messageinfo"))
{
in_prof_msg_messageinfo = false;
}
else if(localName.equalsIgnoreCase("messageid"))
{
in_prof_msg_messageid = false;
}
else if(localName.equalsIgnoreCase("userid"))
{
in_prof_msg_userid= false;
}
else if(localName.equalsIgnoreCase("message"))
{
in_prof_msg_message = false;
}
}
@Override
public void endDocument() throws SAXException
{
super.endDocument();
}
public XMLData getProfileMessageData()
{
Log.v("WHERE","Message_XHandler getProfileMessageData()");
return xml_message;
}
}
Проблема: Журнал: 07-0413: 38: 37.924: VERBOSE / message = (3577): Эй, Амар!Что 07-04 13: 38: 37,934: VERBOSE / сообщение = (3577): '07-04 13: 38: 37,934: VERBOSE / сообщение = (3577): s up?