0

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

Taki
  • 3,290
  • 1
  • 16
  • 41
  • You can load images from url or from files using picasso. Check [this answer](https://stackoverflow.com/a/41157030/5705721). – Makarand Oct 12 '19 at 04:26
  • but if you dont mind , i want to mainly know how to get it from the tag , cause i used getAttributeValue(null,"img"); it didnt work – Taki Oct 12 '19 at 04:46

1 Answers1

0

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

Makarand
  • 983
  • 9
  • 27
  • Thank you for suggesting me this way , but in my case i'm using XmlPullParser , is there any example of getting a tag attribute value using XmlPullParser thank you. – Taki Oct 12 '19 at 14:34
  • Since there is child tag inside the root tag , should i call again ( xpp.getName().equals("childtag") and then assign the value to my view – Taki Oct 12 '19 at 14:51