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 4621892
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:45:56+00:00 2026-05-22T02:45:56+00:00

I wonder how can I retrieve the values inside the Phonebook tags here in

  • 0

I wonder how can I retrieve the values inside the Phonebook tags here in my xml file:

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<SyncDataResponse>
    <Videos>
        <PhonebookVideo>
            <firstname>V Michael</firstname> 
            <lastname>V De Leon</lastname> 
            <Address>V 5, Cat Street</Address> 
            <FileURL>http://cloud.somedomain.com/jm/26.flv</FileURL> 
        </PhonebookVideo>
        <PhonebookVideo>
            <firstname>V John</firstname> 
            <lastname>V Smith</lastname> 
            <Address>V 6, Dog Street</Address> 
            <FileURL>http://cloud.somedomain.com/jm/27.flv</FileURL> 
        </PhonebookVideo>
    </Videos>
    <Phonebook>
        <PhonebookEntry>
            <firstname>Michael</firstname> 
            <lastname>De Leon</lastname> 
            <Address>5, Cat Street</Address> 
            <FileURL>http://www.technobuzz.net/wp-content/uploads/2009/09/Android-Emulator.jpg</FileURL> 
        </PhonebookEntry>
        <PhonebookEntry>
            <firstname>John</firstname> 
            <lastname>Smith</lastname> 
            <Address>6, Dog Street</Address> 
            <FileURL>http://www.cellphonehits.net/uploads/2008/10/android_openmoko.jpg</FileURL> 
        </PhonebookEntry>
        <PhonebookEntry>
            <firstname>Jember</firstname> 
            <lastname>Dowry</lastname> 
            <Address>7, Monkey Street</Address> 
            <FileURL>http://www.techdigest.tv/android.jpg</FileURL> 
        </PhonebookEntry>
        <PhonebookEntry>
            <firstname>Manilyn</firstname> 
            <lastname>Bulambao</lastname> 
            <Address>8, Tiger Street</Address> 
            <FileURL>http://www.ctctlabs.com/staticContent/weblog/xml-android.png</FileURL> 
        </PhonebookEntry>
    </Phonebook>
    <Audios>
        <PhonebookAudio>
            <firstname>A Michael</firstname> 
            <lastname>A De Leon</lastname> 
            <Address>A 5, Cat Street</Address> 
            <FileURL>http://cloud.somedomain.com/jm/a1.mp3</FileURL> 
        </PhonebookAudio>
        <PhonebookAudio> 
            <firstname>A John</firstname> 
            <lastname>A Smith</lastname> 
            <Address>A 6, Dog Street</Address> 
            <FileURL>http://cloud.somedomain.com/jm/a2.mp3</FileURL> 
        </PhonebookAudio>
        <PhonebookAudio> 
            <firstname>A Jember</firstname> 
            <lastname>A Dowry</lastname> 
            <Address>A 7, Monkey Street</Address> 
            <FileURL>http://cloud.somedomain.com/jm/a3.mp3</FileURL> 
        </PhonebookAudio>
    </Audios>
</SyncDataResponse>

My code:

On my main activity (ParsingXML.java), I have something like this:

/* Create a new TextView to display the parsingresult later. */
TextView tv = new TextView(this);
tv.setText("This is the parsing program...");


try {
  /* Create a URL we want to load some xml-data from. */
  URL url = new URL("http://cloud.somedomain.com/jm/sampleXML.xml");
  url.openConnection();
  /* Get a SAXParser from the SAXPArserFactory. */
  SAXParserFactory spf = SAXParserFactory.newInstance();
  SAXParser sp = spf.newSAXParser();

  /* Get the XMLReader of the SAXParser we created. */
  XMLReader xr = sp.getXMLReader();
  /* Create a new ContentHandler and apply it to the XML-Reader*/
  ExampleHandler myExampleHandler = new ExampleHandler();
  xr.setContentHandler(myExampleHandler);

  /* Parse the xml-data from our URL. */
  xr.parse(new InputSource(url.openStream()));
  /* Parsing has finished. */

  /* Our ExampleHandler now provides the parsed data to us. */
  List<ParsedExampleDataSet> parsedExampleDataSet = myExampleHandler.getParsedData();

  /* Set the result to be displayed in our GUI. */
  //tv.setText(parsedExampleDataSet.toString());

  String currentFile = null;
  String currentFileURL = null;
  Iterator i;
  i = parsedExampleDataSet.iterator();
  ParsedExampleDataSet dataItem;
  while(i.hasNext()){

       dataItem = (ParsedExampleDataSet) i.next();
       tv.append("\n" + dataItem.getfirstname());
       tv.append("\n" + dataItem.getlastname());
       tv.append("\n" + dataItem.getAddress());
       tv.append("\n" + dataItem.getFileURL());

       if(dataItem.getparenttag() == "Video"){
            currentFile = dataItem.getfirstname() + ".flv";
       }else if(dataItem.getparenttag() == "PhoneBook"){
            currentFile = dataItem.getfirstname() + ".jpg";
       }else if(dataItem.getparenttag() == "Audio"){
           currentFile = dataItem.getfirstname() + ".mp3";
       }

       currentFileURL = dataItem.getFileURL();
       startDownload(currentFile, currentFileURL);
  }

} catch (Exception e) {
  /* Display any Error to the GUI. */
  tv.setText("Error: " + e.getMessage());

}
/* Display the TextView. */
this.setContentView(tv);

I have this on my handler (ExampleHandler.java):

 private StringBuilder mStringBuilder = new StringBuilder();

 private ParsedExampleDataSet mParsedExampleDataSet = new ParsedExampleDataSet();
 private List<ParsedExampleDataSet> mParsedDataSetList = new ArrayList<ParsedExampleDataSet>();

 // ===========================================================
 // Getter & Setter
 // ===========================================================

 public List<ParsedExampleDataSet> getParsedData() {
      return this.mParsedDataSetList;
 }

 // ===========================================================
 // Methods
 // ===========================================================

 /** Gets be called on opening tags like:
  * <tag>
  * Can provide attribute(s), when xml was like:
  * <tag attribute="attributeValue">*/
 @Override
 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
    if (localName.equals("PhonebookEntry")) {
        this.mParsedExampleDataSet = new ParsedExampleDataSet();
    }

 }

 /** Gets be called on closing tags like:
  * </tag> */
 @Override
 public void endElement(String namespaceURI, String localName, String qName)
           throws SAXException {


      if (localName.equals("PhonebookEntry")) {
           this.mParsedDataSetList.add(mParsedExampleDataSet);
           mParsedExampleDataSet.setparenttag("PhoneBook");
      }else if (localName.equals("firstname")) {
           mParsedExampleDataSet.setfirstname(mStringBuilder.toString().trim());
      }else if (localName.equals("lastname"))  {
          mParsedExampleDataSet.setlastname(mStringBuilder.toString().trim());
      }else if(localName.equals("Address"))  {
          mParsedExampleDataSet.setAddress(mStringBuilder.toString().trim());
      }else if(localName.equals("FileURL")){
          mParsedExampleDataSet.setFileURL(mStringBuilder.toString().trim());
      }

      mStringBuilder.setLength(0);
 }

 /** Gets be called on the following structure:
  * <tag>characters</tag> */
 @Override
public void characters(char ch[], int start, int length) {
      mStringBuilder.append(ch, start, length);
}

And I have this for the dataSet (ParsedExampleDataSet.java)

    private String parenttag = null;
    private String firstname = null;
    private String lastname=null;
    private String Address=null;
    private String FileURL=null;

    //Parent tag
    public String getparenttag() {
         return parenttag;
    }
    public void setparenttag(String parenttag) {
         this.parenttag = parenttag;
    }

    //Firstname
    public String getfirstname() {
         return firstname;
    }
    public void setfirstname(String firstname) {
         this.firstname = firstname;
    }

    //Lastname
    public String getlastname(){
        return lastname;
    }
    public void setlastname(String lastname){
        this.lastname=lastname;
    }

    //Address
    public String getAddress(){
        return Address;
    }
    public void setAddress(String Address){
        this.Address=Address;
    }

    //FileURL
    public String getFileURL(){
        return FileURL;
    }
    public void setFileURL(String FileURL){
        this.FileURL=FileURL;
    }

The output of this code is, since has 4 records inside, it is expected to return 4 records.
And yes, it returned 4 records but it just retrieves the first three records correctly
and then the fourth record is incorrect, the fourth record is actually the record in the PhonebookAudio tag.

It is exactly like this:

This is the parsing program...

Michael
De Leon
5, Cat Street
http://www.technobuzz.net/wp-content/uploads/2009/09/Android-Emulator.jpg

John
Smith
6, Dog Street
http://www.cellphonehits.net/uploads/2008/10/android_openmoko.jpg

Jember
Dowry
7, Monkey Street
http://www.techdigest.tv/android.jpg

A Jember
A Dowry
A 7, Monkey Street
http://cloud.somedomain.com/jm/a3.mp3

I’m kinda new to java and android dev, thank you so much in advanced for any help! 🙂

  • 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-22T02:45:59+00:00Added an answer on May 22, 2026 at 2:45 am

    The firstname, lastname, address and url in the PhoneBookAudio are clobbering the details from the last PhoneBookEntry.

    Either keep track of which state you’re in, so make a note when you enter that you care about what’s happening now and clear the note when you leave , or add a “this.mParsedDataSetList = null” at the end of your endElement handler for a PhoneBookEntry.

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

Sidebar

Related Questions

I wonder how can I search for a certain pattern in file, but only
I wonder if I can execute some programs for different cmd's using .bat file.
I am using cURL to retrieve a file from a server, I wonder is
I wonder how can I create a shadow similar to the one found in
I wonder how can I export a Visual Studio C++ project to Qt? I
Out of curiosity, I wonder what can people do with parsers, how they are
I'd like to start coding for NVIDIA 3D Vision and wonder where can I
wonder whether someone can help me with the following one... I have a struct
I wonder about that can I write native SQL to add or delete operations
I wonder why I can't read the JSON Object like this : { 1:{bulan:Januari,tahun:2012,tagihan:205000,status:Lunas},

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.