The Answer of "Jesse Wilson" is good but in my case I had to preserve de values that returns my parse() method.
List<Article> ArticleNews = parser.parse();
So i added a boolean value;
int countArts;
boolean stopParse;
when i had to stop my parser() method, i consume all the listeners with
if(stopParse)return;
an example:
public List<Article> parse(){
final List<Article> myArticles= new ArrayList<Article>();
final RootElement root = new RootElement("articles");
Element nota = root.getChild("article");
nota.setStartElementListener(new StartElementListener(){
@Override
public void start(Attributes attributes) {
Log.i("----------------------------------------", "START Article!\n");
}
});
nota.setEndElementListener(new EndElementListener(){
public void end() {
if(countArts>9){ //only 10 articles!.
stopParse=true;
}
countArts++;
Log.i("----------------------------------------", "END Article!\n");
}
});
nota.getChild(ID).setEndTextElementListener(new EndTextElementListener(){
public void end(String body) {
if(stopParse)return;
if(Utilities.isNumeric(body)) {
idA = body;
}
}
});
nota.getChild(CATEGORY).setEndTextElementListener(new EndTextElementListener(){
public void end(String body) {
if(stopParse)return;
categoriaA = body;
}
});
nota.getChild(TITLE).setEndTextElementListener(new EndTextElementListener(){
public void end(String body) {
if(stopParse)return;
tituloA = body;
}
});
try {
Xml.parse(this.getInputStream(), Xml.Encoding.UTF_8, root.getContentHandler());
} catch (Exception e) {
Log.e(" *** Exception Xml.parse() ", e.getMessag
}
return myArticles;
}