Extracting and Loading image from XML tag

123 Views Asked by At

I'm using XmlPullParser to parse xml file , i successfully loaded all the other tags but i want to know how to extract the image from this tag and the line of description as shown below

Image

img border='0' 
 src='https://www.eyefootball.com/imghold/thumbChristianEriksen_2019.jpg'>

this line too

<BR>Christian Eriksen has reportedly made the decision to leave Tottenham 
 Hotspur in the New Year after declining to sign a new contract.</p>

this is the whole tag which contains them both

 <description><![CDATA[<p><A 
 HREF='https://www.eyefootball.com/news/42653/Christian-Eriksen-Tottenham- 
 Hotspur-transfer-decision.html'><img border='0' 
 src='https://www.eyefootball.com/imghold/thumbChristianEriksen_2019.jpg'></A> 
 <BR>Christian Eriksen has reportedly made the decision to leave Tottenham 
 Hotspur in the New Year after declining to sign a new contract.</p>]]> </description>

This is how i'm getting the data from xml

     try {
            URL url = new URL("https://www.eyefootball.com/football_news.xml");

            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();

            factory.setNamespaceAware(false);

            XmlPullParser xpp = factory.newPullParser();

            xpp.setInput(GetInputStream(url), "utf-8");

            boolean insideItem = false;

            int eventType = xpp.getEventType();

            while (eventType != XmlPullParser.END_DOCUMENT) {

                if (eventType == XmlPullParser.START_TAG) {

                    if (xpp.getName().equalsIgnoreCase("item")) {
                        insideItem = true;
                    } else if (xpp.getName().equalsIgnoreCase("title")) {
                        if (insideItem) {
                            rssModel.setTitle(xpp.nextText());
                        }
                    } else if (xpp.getName().equalsIgnoreCase("pubDate")) {
                        if (insideItem) {
                            rssModel.setPublished(xpp.nextText());
                        }
                    } else if (xpp.getName().equalsIgnoreCase("guid")) {
                        if (insideItem) {
                            rssModel.setLinks(xpp.nextText());
                        }
                    } else if (xpp.getName().equalsIgnoreCase("description")) {
                     /// i want to get the child tags ( img and last line ) from  
                     /// descritpion tag
                    }

                } else if (eventType == XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")) {

                    insideItem = false;

                    list.add(rssModel);

                }
                eventType = xpp.next();

            }


        } catch (MalformedURLException e) {
            exception = e;
        } catch (XmlPullParserException e) {
            exception = e;
        } catch (IOException e) {
            exception = e;
        }

    }

Thank you

1

There are 1 best solutions below

2
Makarand On

Ok, First extract your tag like done here

and then you can load images from url or from files using picasso. Check this answer

Check this link for dealing with child node https://stackoverflow.com/a/11588872/5705721