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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:22:43+00:00 2026-06-04T13:22:43+00:00

Following code is written to fetch the data from the xml file. I think

  • 0

Following code is written to fetch the data from the xml file. I think it does fetch but in the object form. Why is that ?

package newpackage;

import java.io.File;
import java.util.Iterator;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import java.util.LinkedList;

public class xmlParser {


private DocumentBuilder db;
private DocumentBuilderFactory dbf;
private Document dom;
private LinkedList list = new LinkedList();

public static void main(String args[]) {
    xmlParser o = new xmlParser();
    o.parseXML();
    o.parseDocument();
    o.print();
}

public void parseXML() { // getting a document builder
    try {
        dbf = DocumentBuilderFactory.newInstance();
        db = dbf.newDocumentBuilder();
        dom = db.parse(new File("Details.xml"));
    } catch(Exception exc) {
        exc.printStackTrace();
    }
}

public void parseDocument() { // get a list of student elements
    Element docEle = dom.getDocumentElement();
    NodeList nl = docEle.getElementsByTagName("Details");
    if(nl != null && nl.getLength() > 0) {
        for(int i=0;i<nl.getLength();i++) {
            Element el = (Element)nl.item(i);
           Details details = new Details();
           details = details.getDetail(el);
           list.add(details);
        }
    }
}

public void print() {
 //        list.iterator();
 //        while(!list.isEmpty()) {
 //            System.out.println(list.pop().toString());
 //        }

      Iterator it = list.iterator();
      while(it.hasNext()) {
          System.out.println(it.next().toString());
      }

  }    
}

Output :

newpackage.Details@1ac3c08
newpackage.Details@9971ad
newpackage.Details@1f630dc
newpackage.Details@1c5c1

Why do i get the output in the object form even after applying toString ?

  • 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-04T13:22:45+00:00Added an answer on June 4, 2026 at 1:22 pm

    Why do i get the output in the object form even after applying toString ?

    Because you didn’t override toString() method for that Details class

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

Sidebar

Related Questions

I'm trying to use the following code (poorly written, but it's just a proof
I have written a following code to get just the file name without extension
I have written the following code. But it is removing only &nbsp; not <br>
I have written the following while loop in a php file. The file does
I have written some data fetch service which fetches some entities from main web
I have the following segment of code that someone else has written, and that
I'm using some not optimal code written by me... :-| I have following code:
I have written following code to attach gesture recogniser to multiple imageviews. [imageview1 setUserInteractionEnabled:YES];
I have written a code and i'm pretty much stuck. In the following code,
I am trying my hands on WPF MVVM. I have written following code in

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.