I'd like some help on a problem I'm having in Java Android .
I first read a String XML to get the values for each tag. When getting the values reads the tags well, only 9 out of 9 Strings received reads in parts, if anyone knows how to solve thank you for the help.
Next I present the code I use to read XML.
SAXParser saxParser = saxParserFactory.newSAXParser();
Parse_xml parseXMLClass = new Parse_xml();
saxParser.parse(new InputSource(new StringReader(message_posted)), parseXMLClass);
The following is the class that reads the tags:
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException
{
if (localName.equalsIgnoreCase("MSG"))
{
if (listMSG == null)
{
listMSG = new ArrayList<MSG>();
}
}
if (localName.equalsIgnoreCase("Delete"))
{
if (listMSG == null)
{
listMSG = new ArrayList<MSG>();
}
}
if (localName.equalsIgnoreCase("Clear"))
{
if (listMSG == null)
{
listMSG = new ArrayList<MSG>();
}
}
if (localName.equalsIgnoreCase("ID"))
{
bID = true;
}
if (localName.equalsIgnoreCase("DESTINATION"))
{
bDestination = true;
}
if (localName.equalsIgnoreCase("SOURCE"))
{
bSource = true;
}
if (localName.equalsIgnoreCase("DATE"))
{
bDate = true;
}
if (localName.equalsIgnoreCase("SUBJECT"))
{
bSubject = true;
}
if (localName.equalsIgnoreCase("BODY"))
{
bMessage = true;
}
if (localName.equalsIgnoreCase("SMS"))
{
bType = true;
}
if (localName.equalsIgnoreCase("TTL"))
{
config = new Configuration();
bTtl = true;
}
if (localName.equalsIgnoreCase("ATTEMPTS"))
{
bAttempet = true;
}
if (localName.equalsIgnoreCase("SMTP"))
{
bSmtp = true;
}
if (localName.equalsIgnoreCase("PORT"))
{
bPort = true;
}
if (localName.equalsIgnoreCase("USERNAME"))
{
bUsername = true;
}
if (localName.equalsIgnoreCase("PASSWORD"))
{
bPass = true;
}
if (localName.equalsIgnoreCase("EMAIL"))
{
bEmail = true;
}
if (localName.equalsIgnoreCase("STATUS"))
{
bStatus = true;
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException
{
if (localName.equalsIgnoreCase("MSG"))
{
listMSG.add(msg);
msg = new MSG();
}
if (localName.equalsIgnoreCase("DELETE"))
{
listMSG.add(msg);
msg = new MSG();
}
if (localName.equalsIgnoreCase("Clear"))
{
listMSG.add(msg);
msg = new MSG();
}
}
@Override
public void characters(char ch[], int start, int length)
throws SAXException
{
*/
if (bID)
{
String id=String.copyValueOf(ch, start, length).trim();
msg.setId(Integer.parseInt(id));
bID = false;
}
if (bDestination)
{
String destinaton=String.copyValueOf(ch, start, length).trim();
msg.setDestination(destinaton);
bDestination = false;
}
if (bSource)
{
String source=String.copyValueOf(ch, start, length).trim();
msg.setSource(source);
bSource = false;
}
if (bDate)
{
String date=String.copyValueOf(ch, start, length).trim();
msg.setDate(date);
bDate = false;
}
if (bSubject)
{
String subject=String.copyValueOf(ch, start, length).trim();;
msg.setSubject(subject);
bSubject = false;
}
if (bMessage)
{
String body=String.copyValueOf(ch, start, length).trim();
msg.setbody(body);
bMessage = false;
}
if (bType)
{
String type=String.copyValueOf(ch, start, length).trim();
msg.setType(Integer.parseInt(type));
bType = false;
}
if (bStatus)
{
String status=String.copyValueOf(ch, start, length).trim();
msg.setStatus(Integer.parseInt(status));
bStatus = false;
}
if (bTtl)
{
String ttl=String.copyValueOf(ch, start, length).trim();
config.setTtl(Integer.parseInt(ttl));
bTtl = false;
}
if (bAttempet)
{
String attempt=String.copyValueOf(ch, start, length).trim();
config.setAttempt(Integer.parseInt(attempt));
bAttempet = false;
}
if (bSmtp)
{
String smtp=String.copyValueOf(ch, start, length).trim();
config.setSmtp(smtp);
bSmtp = false;
}
if (bPort)
{
String porta=String.copyValueOf(ch, start, length).trim();
config.setPorta(Integer.parseInt(porta));
bPort = false;
}
if (bUsername)
{
String username=String.copyValueOf(ch, start, length).trim();
config.setUsername(username);
bUsername = false;
}
if (bPass)
{
String pass=String.copyValueOf(ch, start, length).trim();
config.setPass(pass);
bPass = false;
}
if (bEmail)
{
String email=String.copyValueOf(ch, start, length).trim();
config.setEmail(email);
bEmail = false;
}
}