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

  • SEARCH
  • Home
  • 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 7675781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:02:32+00:00 2026-05-31T17:02:32+00:00

Possible Duplicate: Best XML Parser for PHP Using JAXB with Google Android I need

  • 0

Possible Duplicate:
Best XML Parser for PHP
Using JAXB with Google Android

I need to add a simple functionality into my Android app.

I must connect to this fictional script: http://test/getMagazinesList.php

The script will return me a XML file like this:

<magazines>
 <magazine title="APP 1" id="1">
  <description>Prueba real</description>
   <miniature>http://web/miniature.jpg</miniature>
 </magazine>
 <magazine title="APP 2" id="2">
  <description>Prueba real 2</description>
   <miniature>http://web/miniature2.jpg</miniature>
 </magazine>
 <magazine title="APP 3" id="3">
  <description>Prueba real 3</description>
   <miniature>http://web/miniature3.jpg</miniature>
 </magazine>
</magazines>

The objective is to store all the info of the XML in a List of these MagazinePreview objects:

public class MagazinePreview {
String title;
String id;
String description;
String miniatureUrl;
Bitmap miniature;
public MagazinePreview(String title, String id, String description,
        String miniatureUrl) {
    super();
    this.title = title;
    this.id = id;
    this.description = description;
    this.miniatureUrl = miniatureUrl;
    }   
}

Which is the easiest approach to connect to that PHP and get the XML and interpret it storing the info on the List of MagazinePreview class objects?

Thanks

  • 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-05-31T17:02:33+00:00Added an answer on May 31, 2026 at 5:02 pm

    You can use Simple XML for this.

    Adorn your MagazinePreview class with these annotations:

    public class MagazinePreview 
    {
      @Attribute
      String title;
      @Attribute
      String id;
      @Element
      String description;
      @Element(name="miniatura")
      String miniatureUrl;
      Bitmap miniature;
      public MagazinePreview(String title, String id, 
                             String description, String miniatureUrl) 
      {
        super();
        ...
      }   
    }
    

    Now add a class for your collection of magazines. Add a method that performs deserialization of an XML string, instantiating your objects as it does so:

    @Root
    public class MagazinePreviews
    {
      @ElementList(name="magazines")
      ArrayList<MagazinePreviews> previews;
    
      public static MagazinePreviews Load(String xml)
      {
        Serializer serializer = new Persister();
        return serializer.read(MagazinePreviews.class, xml);
      }
    }
    

    This will get you a MagazinePreviews instance with your MagazinePreview instances in it. Simple XML does all the heavy lifting. It will use the annotations (@Element, @Attribute) to know which data to place in which fields.

    You’ll still need a way to connect to your PHP server script. Assuming it’s a script that simply returns a string of XML, you could use this:

    public String getXML() throws Exception
    {
      StringBuilder builder = new StringBuilder();
      HttpClient httpclient = new DefaultHttpClient();
      HttpGet httpget = new HttpGet("myscript.php");
      HttpResponse response = httpclient.execute(httpget);
      int statuscode = response.getStatusLine().getStatusCode();
      if(statuscode == 200)
      {
        HttpEntity entity = response.getEntity();
        InputStream content = entity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(content));
        String line;
        while ((line = reader.readLine()) != null)  builder.append(line);               
      }
      else throw new Exception("HTTP error: " + String.valueOf(statuscode));
      return builder.toString();
    }
    

    This code calls your PHP script on the server, retrieves the response (assumed to be an XML string), or throws an error if the request fails.

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

Sidebar

Related Questions

Possible Duplicate: Best XML Parser for PHP I have an XML code like as
Possible Duplicate: Best XML Parser for PHP -----First XML-----str1 <HOME> <USER_DETAIL> <LOCATION><![CDATA[MUMBAI]]></LOCATION> <NAME><![CDATA[RAVI]]></NAME> <ID><![CDATA[101]]></ID>
Possible Duplicate: Best XML Parser for PHP I'm submitting a form which returns an
Possible Duplicate: Best XML Parser for PHP I have a string with XML data
Possible Duplicate: Best way to stop SQL Injection in PHP I need to secure
Possible Duplicate: Best way to periodically execute a PHP script? I need to run
Possible Duplicate: Best way to stop SQL Injection in PHP I'd like a simple
Possible Duplicate: Best way to stop SQL Injection in PHP I am creating a
Possible Duplicate: Best way to stop SQL Injection in PHP I have seen some
Possible Duplicate: Best practice: Import mySQL file in PHP; split queries How to import

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.