Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8618459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:06:58+00:00 2026-06-12T06:06:58+00:00

I am having some problems retrieving a xml from url with the following code:

  • 0

I am having some problems retrieving a xml from url with the following code:

    private static String getAlbumArt(String artistName, String albumName){
        try{
        XMLParser xml_parser = new XMLParser();
        String xml = xml_parser.getXmlFromUrl(getAlbumURL(artistName, albumName));
        Document doc = xml_parser.getDomElement(xml);
        NodeList N = doc.getElementsByTagName("album");
        Node node = N.item(0);
        NodeList N2 = node.getChildNodes();
        System.out.println("1------");
            for (int i = 0; i < N2.getLength(); i++) {
                Node detailNode = N2.item(i);
                if (detailNode.getNodeType() == Node.ELEMENT_NODE)
                    {
                    System.out.println("2------");
                    if (detailNode.getNodeName().equalsIgnoreCase("image")) 
                    {
                        String sizeVal = ((Element) detailNode).getAttribute("size");
                        String url = detailNode.getTextContent();
                        if (sizeVal.equalsIgnoreCase("large")) {
                            return url;
                        }
                    }
                    }
        }
        }
        catch (Exception e){
        }
        return null;
    }

The xml function which i call in the above code:

public String getXmlFromUrl(String url) {
    String xml = null;
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        xml = EntityUtils.toString(httpEntity);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return xml;
}

getAlbumURL:

    public static String getAlbumURL(String artist, String album){
        return URL_METHOD + METHOD_GETALBUM + AMPERSAND
                + API_KEY + AMPERSAND
                + PARAM_ARTIST + artist + AMPERSAND
                + PARAM_ALBUM + album;
    }

XMLparser:

public class XMLParser {

// constructor
public XMLParser() {
}

//Get XML from URL
public String getXmlFromUrl(String url) {
    String xml = null;
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        xml = EntityUtils.toString(httpEntity);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return xml;
}

//Get dom element
public Document getDomElement(String xml){
    Document doc = null;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {

        DocumentBuilder db = dbf.newDocumentBuilder();
        InputSource is = new InputSource();
            is.setCharacterStream(new StringReader(xml));
            doc = db.parse(is); 

        } catch (ParserConfigurationException e) {
            Log.e("Error: ", e.getMessage());
            return null;
        } catch (SAXException e) {
            Log.e("Error: ", e.getMessage());
            return null;
        } catch (IOException e) {
            Log.e("Error: ", e.getMessage());
            return null;
        }

        return doc;
}

//Get nod element
 public final String getElementValue(Node elem ) {
     Node child;
     if( elem != null){
         if (elem.hasChildNodes()){
             for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() ){
                 if( child.getNodeType() == Node.TEXT_NODE  ){
                     return child.getNodeValue();
                 }
             }
         }
     }
     return "";
 }

//Get element value
 public String getValue(Element item, String str) {     
     NodeList nlList = item.getElementsByTagName(str).item(0).getChildNodes();
     Node nValue = (Node) nlList.item(0);
     return nValue.getNodeValue();
    }

}

Any ideas ? I seriously don’t know what is wrong.. I used this before and it worked.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:07:00+00:00Added an answer on June 12, 2026 at 6:07 am

    I pulled your code and tried it out. I redid the “getAlbumURL” to return a hardcoded string. I used the address you provided in the comments, it failed. However, that xml doesn’t link to any album art. So I tried the proper album name, “In%20ra*i*nbows.” Worked like a dream.

    So first, verify that your constants are giving you what you think they should (which you already did) and second, verify your test data. Your code appears to be fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some problems with the following code: with open('townhall.map', 'r') as f: for
I'm having some problems retrieving data from a multidimensional array. I have something like
For some reason I'm having a problem retrieving data from my database. It leaves
Im having some problems understanding some code in a programme I have inherited. CGPoint
For some reason I'm having a problem retrieving data from my database. It leaves
Having some problems with my given code. Thou it works accordingly, im required to
Im having some problems parsing a string to a textbox type, im using the
Just having some problems redirecting urls. urls.py url(r'^index\.asp$', views.Redirect, name='redirect'), views.py pageID = {
Hi i am having some problems retreiving data from the datastore... I have a
Currently having some problems- now = datetime.datetime.now() month = now.strftime(%B) site = wikipedia.getSite('en', 'wikiquote')

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.