1

hey guys I want to display artist info on android so i tried to parse xml but there is odd tag like this " CDATA "before summary of artist so when i run my code i got blank text view I trie for Json but its out of my capacity to write json parsing

here is my code

 String URL = "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=b25b959554ed76058ac220b7b2e0a026&limit=" + 1 + "&page=" + 1;
        XmlParser parser = new XmlParser();
        String xml = parser.getXmlFromUrl(URL); // getting XML
        Document doc = parser.getDomElement(xml); // getting DOM element
                            NodeList nl = doc.getElementsByTagName("artist");
             for (i = 0; i < nl.getLength(); i++) 
             {
                    Element e = (Element) nl.item(i);
                     name = parser.getValue(e, KEY_NAME);// name child value
                        image = parser.getValue(e, KEY_IMAGE);
                        summary = parser.getValue(e, KEY_Summary);
                                            return summary;
        } 
            return null;
    }
            @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
                    URL thumb_u;
            try {
                thumb_u = new URL(result);
                  Drawable thumb_d = Drawable.createFromStream(thumb_u.openStream(), "src");
                  tv.setText(result);//textview text set
                    icon.setImageDrawable(thumb_d);
Swap-IOS-Android
  • 4,363
  • 6
  • 49
  • 77

1 Answers1

0

Where does XmlParser come from? I googled and I'm guessing it came from here? If so, change

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

to add this line in getDomElement:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setCoalescing(true);

Docs: setCoalescing

noisecapella
  • 814
  • 7
  • 17
  • Sir you are right I follow that tutorial ..i have added the line as you suggest to add me but still i dont get any text on my textview...still its just blank ..is this code is fine NodeList nl = doc.getElementsByTagName("artist");..for reference you can take a look at lastfm site into api page you will find artistinfo link so you will get better xml view – Swap-IOS-Android Sep 25 '12 at 08:24
  • What isn't working? Note that you should only see one artist summary. Your code will also iterate through the `artist` tags in the `similar` tag, which don't contain summary tags – noisecapella Sep 26 '12 at 16:16
  • so how could i write code to get summary from lasfm getinfo artist? – Swap-IOS-Android Sep 26 '12 at 16:38
  • You would need to call the API for each artist in that list. The [API](http://www.last.fm/api/show/artist.getInfo) doesn't show any way to return summaries for every similar artist – noisecapella Sep 26 '12 at 16:42
  • But to get artistinfo you just need apk key .. i have API key just you need to add artist name and API into your url and pass it to parser . i think you dont need to use api ? if i am right – Swap-IOS-Android Sep 27 '12 at 07:56