Personal here in the project where I use classes to read an XML works, the problem is that it is not loading the whole message string, what can it be? Eg: in the provider has text, and is only showing on the screen to the user only up to a certain point, I already manually tested the same size playing in an alert builder, and it worked. the problem is really in reading the XML, see my classes:
package br.com.insideweb.xml;
/**
* Classe para retornar os dados do xml / xml data reader
*
*/
public class XmlReader {
private String rssUrl;
/**
* Constructor
*/
public XmlReader(String rssUrl) {
this.rssUrl = rssUrl;
}
/**
* Pega uma lista de XML.
*
* @return
*/
public List<ItemXml> getItems() throws Exception {
// SAX parse RSS data
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
XmlParseHandler handler = new XmlParseHandler();
saxParser.parse(rssUrl, handler);
return handler.getItems();
}
}
/**Classe para tratar o xml / parse handler */
public class XmlParseHandler extends DefaultHandler {
private List<ItemXml> rssItems;
// Used to reference item while parsing
private ItemXml currentItem;
// usa o id notificador
private boolean parsingId;
// Usa mensagem notificador
private boolean parsingMensagem;
public XmlParseHandler() {
rssItems = new ArrayList<ItemXml>();
}
public List<ItemXml> getItems() {
return rssItems;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if ("notificacoes".equals(qName)) {
currentItem = new ItemXml();
} else if ("id".equals(qName)) {
parsingId = true;
} else if ("mensagem".equals(qName)) {
parsingMensagem = true;
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if ("notificacoes".equals(qName)) {
rssItems.add(currentItem);
currentItem = null;
} else if ("id".equals(qName)) {
parsingId = false;
} else if ("mensagem".equals(qName)) {
parsingMensagem = false;
}
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (parsingId) {
if (currentItem != null)
currentItem.setId(new String(ch, start, length));
} else if (parsingMensagem) {
if (currentItem != null) {
currentItem.setMensagem(new String(ch, start, length));
parsingMensagem = false;
}
}
}
}
package br.com.insideweb.model;
/**Classe de entidade do xml*/
public class ItemXml {
// item id
private String id;
// item mensagem
private String mensagem;
@Override
public String toString() {
return ""+mensagem;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getMensagem() {
return mensagem;
}
public void setMensagem(String mensagem) {
this.mensagem = mensagem;
}
}
/**
* Tela para ler a notificação */
@SuppressLint("NewApi")
public class ReaderNotificacao extends Activity {
private AlertDialog.Builder msg;
private AlertDialog alert;
@SuppressLint("NewApi") @Override
protected void onCreate(android.os.Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getActionBar();
actionBar.hide();
// ler o xml
lerNotificacoes();
}
// Vai carregar as notificações
public void lerNotificacoes() {
try {
XmlReader reader = new XmlReader("meuxml.xml");
msg = new AlertDialog.Builder(this);
msg.setTitle("Notificação");
msg.setMessage(""+reader.getItems());
msg.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
AlertDialog alert = msg.create();
alert.show();
} catch (Exception e) {
}
}
The problem is just that it does not load complete message string.