0
votes

I am trying to parse this RSS feed, for now i can get everything but my only prolem is with the image.

How can i extract the image while it's inside another XML tag ?

  <?xml version="1.0" encoding="utf-8"?>
  <!-- generator="Joomla! 1.5 - Open Source Content Management" -->
  <?xml-stylesheet href="/plugins/system/plg_jausersetting/style.css" type="text/css"?>
  <?xml-stylesheet href="/media/system/css/modal.css" type="text/css"?>
  <?xml-stylesheet href="/components/com_jcomments/tpl/default/style.css?v=12" type="text/css"?>
  <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
    <title>Accueil</title>
    <description>Annuaire, guide de voyage et magazine culturel en Tunisie : Maisons d'hôtes, hôtels de charmes, gites, restaurants, boutiques, idées cadeaux, musées, monuments, marinas, golf, thalasso ou Spa? Trouvez toutes les bonnes adresses, itinéraires conseillées, cityguide ainsi que l’agenda culturel sur mille-et-une-tunisie.com</description>
    <link>http://www.mille-et-une-tunisie.com/component/content/frontpage.html</link>
    <lastBuildDate>Fri, 05 Oct 2012 10:47:59 +0000</lastBuildDate>
    <generator>Joomla! 1.5 - Open Source Content Management</generator>
    <language>fr-fr</language>
    <item>
        <title>Sehl Zargouni: &quot;Le contrôle est effectué par l’ONTT mais dans les prochains mois, il se fera conjointement avec notre association &quot; </title>
        <link>http://www.mille-et-une-tunisie.com/accueil/rencontres/3761-sehl-zargouni-qle-controle-est-effectue-par-lontt-mais-dans-les-prochains-mois-il-se-fera-conjointement-avec-notre-association-q-.html</link>
        <guid>http://www.mille-et-une-tunisie.com/accueil/rencontres/3761-sehl-zargouni-qle-controle-est-effectue-par-lontt-mais-dans-les-prochains-mois-il-se-fera-conjointement-avec-notre-association-q-.html</guid>
        <description><![CDATA[<p style="text-align: justify;"><img src="http://www.mille-et-une-tunisie.com/images/stories/Mille-et-une-Tunisie/1001-Accueil/Rencontres/LogoEdhiafa.jpg" border="0" width="541" height="400" style="float: left;" />Il y a un peu moins d’un an l’association Edhiafa réunissant les  propriétaires de maisons d’hôtes, gîtes et hôtel de charme du pays  recevait son agrément officiel de création. Son président Sehl Zargouni  nous parle de cette première année d’existence</p>
  ]]>
</channel>

1
The xml seems not valid to me, it is part of the description indeed but as the xml above shows </description> is missing. Please post the correct valid xml. Also maybe log the output to be more clear - QVDev

1 Answers

1
votes

Ok - I had this problem too!

Try This :

at first make a string variable like :

   String cdata ="";

then create this:

 public final String getElementValue2( Node elem ) {  
 Node child;  
 if( elem != null){  
     if (elem.hasChildNodes()){  
         for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() ){   
             if(child.getNodeType() == Node.CDATA_SECTION_NODE){ 
                 CDATASection cdata = (CDATASection)child;
                 cdata =cdata.getData().toString();
             }  
         }  
     }  
 }  

afterward use this function :

  public String getValue2(Element item, String str)
 {  
         //NodeList n = item.getElementsByTagName(str);  
         //String ses = this.getElementValue1(n.item(0));  
         //String mim =ses.replaceAll("(?s)\\<.*?\\>", "\n");  
         return cda.replaceAll("<p>","").replaceAll("</p>",""); 
 }