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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:47:18+00:00 2026-05-20T23:47:18+00:00

In this method, an XML file is read and certain information about it is

  • 0

In this method, an XML file is read and certain information about it is put into a list. I have everything else working for all of the code/other methods, I am just having trouble returning the “list” variable.

package ca3;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.w3c.dom.Document;
import org.w3c.dom.*;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

public class xmlReader{

    public String fileName;
    public xmlReader (String fileLoca){
        fileName=fileLoca;
    }

    public List list;

    public List returnLists(String fileN)
    {
        mp3Lister woww = null;
        String fName;
        String lName;
        mp3Lister qwewq;
    try {
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            Document doc = docBuilder.parse (new File(fileN));

            // normalize text representation
            doc.getDocumentElement ().normalize ();
            System.out.println ("Root element of the doc is " +
                 doc.getDocumentElement().getNodeName());

            NodeList listOfPersons = doc.getElementsByTagName("person");
            int totalPersons = listOfPersons.getLength();
            System.out.println("Total no of people : " + totalPersons);
            List list = new LinkedList();    // Doubly-linked list

            for(int s=0; s<listOfPersons.getLength() ; s++){
                Node firstPersonNode = listOfPersons.item(s);
                if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){
                    Element firstPersonElement = (Element)firstPersonNode;

                    //-------
                    NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
                    Element firstNameElement = (Element)firstNameList.item(0);

                    NodeList textFNList = firstNameElement.getChildNodes();
//                    System.out.println("First Name : " +
//                           ((Node)textFNList.item(0)).getNodeValue().trim());

//                            
                    //-------
                    NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
                    Element lastNameElement = (Element)lastNameList.item(0);

                    NodeList textLNList = lastNameElement.getChildNodes();
//                    System.out.println("Last Name : " +
//                           ((Node)textLNList.item(0)).getNodeValue().trim());

                    lName = textLNList.item(0).getNodeValue().trim().toString();
                    fName = textFNList.item(0).getNodeValue().trim().toString();
                    mp3Lister[] wowow = null;

                    woww = new mp3Lister(fName,lName);

                    list.add(woww);
                    //----

                    //------

                }//end of if clause

//                qwewq = (mp3Lister) list.get(0);
//                System.out.println(qwewq.getTitle() + " wakakakakaka");

            }//end of for loop with s var
            //end of for loop with s var

        }catch (SAXParseException err) {
        System.out.println ("** Parsing error" + ", line "
             + err.getLineNumber () + ", uri " + err.getSystemId ());
        System.out.println(" " + err.getMessage ());

        }catch (SAXException e) {
        Exception x = e.getException ();
        ((x == null) ? e : x).printStackTrace ();

        }catch (Throwable t) {
        t.printStackTrace ();
        }

return list;
        //System.exit (0);

    }
}
  • 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-20T23:47:18+00:00Added an answer on May 20, 2026 at 11:47 pm

    I assume that you meant to return the list local variable that you declare in the returnLists function. What you’ll be getting back is actually the class variable, also called list. This is because the local list variable has gone out of context by the time the code reaches your return statement (the local list variable is within the context of the try block you have declared). If you want to return the value from the local list variable change the first couple of lines of returnLists to this:

    public List returnLists(String fileN)
        {
            mp3Lister woww = null;
            String fName;
            String lName;
            mp3Lister qwewq;
            List list = new LinkedList();
        try {
    

    and then remove the declaration of the list variable inside the try block.

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

Sidebar

Related Questions

I have read an xml file into a char [] and am trying to
When I parse my xml file (variable f) in this method, I get an
I have an xml file that I am using linq-to-XML to read. Linq-to-XML is
I'm loading an XML file with this method: public static String readTextFile(String fullPathFilename) throws
I have this method on a webpart: private IFilterData _filterData = null; [ConnectionConsumer(Filter Data
Currently i have this method: static boolean checkDecimalPlaces(double d, int decimalPlaces){ if (d==0) return
I have this method in my db class public function query($queryString) { if (!$this->_connected)
I have this method: public bool CanExecute() And after 70 commits, I added an
I have this method Verify_X which is called during databind for a listbox selected
I'm trying to read XML file, ex : <entry> <title>FEED TITLE</title> <id>5467sdad98787ad3149878sasda</id> <tempi type="application/xml">

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.