Getting the image url from a xml files seems tricky, in Android Studio. Trying to categorise the image url of 30 RSS Feed xmls, i found that 95% of them are using ".jpg" images and the link alwayas begins with "http", not "www.". So, im tryingto write a piece of code that:
- Is getting one node (see xml_part), from the nodelist of "item" nodes of the xml file, into a string.
- From the begings of the string reach the point of ".jpg" and cut out the rest of the string.
- From that ".jpg" point and backwards reach the "http" point and cut out the rest of the string.
- Save the image url for later use.
xml_part
<item> <title>Πάνω από 1 στα 3 νοικοκυριά ζει με ετήσιο εισόδημα κάτω από 10.000 ευρώ</title> <link>http://tvxs.gr/news/ellada/pano-apo-1-sta-3-noikokyria-zei-me-etisio-eisodima-kato-apo-10000-eyro</link> <description><p>Συντριπτικά αρνητικές είναι οι προσδοκίες των νοικοκυριών καθώς το 70% αναμένει επιδείνωση της οικονομικής του κατάστασης και μόνο το 5,1% προσδοκά σε βελτίωση των οικονομικών του δυνατοτήτων, όπως προκύπτει από την <strong>έρευνα</strong> του Ινστιτούτου Μικρών Επιχειρήσεων της <strong>ΓΣΕΒΕΕ</strong> για το <strong>εισόδημα</strong> και τις <strong>δαπάνες</strong> των νοικοκυριών για το <strong>2015</strong>.</p> <div class="field field-type-filefield field-field-article-image"> <div class="field-items"> <div class="field-item odd"> <img src="http://im2ns5.27210.gr/sites/default/files/imagecache/280x/article/2016/03/194269-ellada-krisi-oikonomia-anergia.jpg" alt="" title="" class="imagecache imagecache-280x imagecache-default imagecache-280x_default" width="280" height="175" /> </div> </div> </div> <p><a href="http://tvxs.gr/news/ellada/pano-apo-1-sta-3-noikokyria-zei-me-etisio-eisodima-kato-apo-10000-eyro" target="_blank">διαβάστε περισσότερα</a></p></description> <category domain="http://tvxs.gr/taxonomy/term/2">Ελλάδα</category> <category domain="http://tvxs.gr/taxonomy/term/78458">ΓΣΕΒΕΕ έρευνα ετήσιο οικογενειακό εισόδημα Δεκέμβριος 2015</category> <category domain="http://tvxs.gr/taxonomy/term/78459">μείωση εισοδημάτων Ελλάδα νοικοκυριά 2015</category> <pubDate>Thu, 21 Jan 2016 15:09:50 +0000</pubDate> <dc:creator>Ειρήνη Ορφανίδου</dc:creator> <guid isPermaLink="false">194269 at http://tvxs.gr</guid> </item> My piece of code
String WholeNode = nl.item(i).getNodeValue(); int WholeNode_length = WholeNode.length(); for (int WN = 0; WN < WholeNode_length; WN++) { String JPGChecker = WholeNode.substring(WN,WN+4); if (JPGChecker.equals(".jpg")) { WholeNode = WholeNode.substring(0,WN+4); WholeNode_length = WholeNode.length(); } } for (int SN = WholeNode_length; SN > 0; SN--) { String HTTPChecker = WholeNode.substring(SN-4, SN); if (HTTPChecker.equals("http")) { WholeNode = WholeNode.substring(SN, WholeNode_length); WholeNode_length = WholeNode.length(); } } _item.setImage(WholeNode); Doesn't work and can't see why, please help the newbie.
The other 5% of xmlcategorization is in which the image is not .jpg (easily changing the above code include other image formats) and other cases in which the url is not "from the top" but after the "http://www.antikoukou.com/" for ex.
No comments:
Post a Comment