J'essaye d'analyser rss xml, mais coincé dans l'analyse de la description, comme mon programme cesse d'analyser le contenu de la description quand il rencontre (').
xml analyse en utilisant SAX parser en Java
Code pour parser xml:
public class RSSAX {
String channel_title="";
public void displayRSS()
{
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
sp.parse("http://www.ronkaplansbaseballbookshelf.com/feed/podcast/", new RSSHandler());
} catch (Exception e) {
// TODO: handle exception
System.out.println("Messge is "+e.getMessage());
}
}
private class RSSHandler extends DefaultHandler
{
private boolean isItem = false;
private String tagName="";
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
this.tagName= qName;
if(qName.equals("item"))
{
this.isItem=true;
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
this.tagName="";
if(qName.equals("item"))
{
System.out.println("========================");
this.isItem=false;
}
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
if(this.isItem)
{
//System.out.println("tagname is "+this.tagName);
if(this.tagName.equals("title"))
{
System.out.println("title is "+(new String(ch,start,length)));
this.tagName="";
}
else if(this.tagName.equals("link"))
{
System.out.println("link is "+(new String(ch,start,length)));
this.tagName="";
}
else if(this.tagName.equals("description"))
{
String test=(new String(ch,start,length)).replaceAll("\\<.*?>","");
test=StringEscapeUtils.escapeXml(StringEscapeUtils.unescapeXml(test));
System.out.println("description is "+test);
this.tagName="";
}
else if(this.tagName.equals("comments"))
{
System.out.println("comment link is "+(new String(ch,start,length)));
this.tagName="";
}
else if(this.tagName.equals("pubDate"))
{
System.out.println("pubDate is "+(new String(ch,start,length)));
this.tagName="";
}
else if(this.tagName.equals("category"))
{
System.out.println("Category is "+(new String(ch,start,length)));
this.tagName="";
}
else if(this.tagName.equals("content:encoded"))
{
System.out.println("content:encoded is "+(new String(ch,start,length)));
//this.tagName="";
}
}
}
}
Sortie: titre
est Conversation Bibliothèque: Filip Bondy
lien est http://www.ronkaplansbaseballbookshelf.com/2015/08/04/the-bookshelf-conversation-filip-bondy/
pubDate est Mar 4 août 2015 14:31:45 +0000
lien commentaire est http://www.ronkaplansbaseballbookshelf.com/2015/08/04/the-bookshelf-conversation-filip-bondy/#comments
Catégorie est 2015 Titre Catégorie est l'auteur profil/interview de Ron Kaplan
Description est My New Jersey Landsman et sportif vétéran Filip Bondy a conçu un volume amusant sur un des plus célèbres jeux dans l'histoire du passe-temps national. Chaque fois qu'il ya
Il arrête l'analyse de la description quand il rencontre il y a ..
ce qui est l'exception? – eis