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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:58:30+00:00 2026-06-07T02:58:30+00:00

I want to populate a Drop Down list via an XML File. I have

  • 0

I want to populate a Drop Down list via an XML File.
I have crated the XML File already and the code i have written firstly to read the xml file and just give me the items from the xml file is compiliing but giving me errors when i want to run the code later.

public ArrayList readXML(){

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db;

        try {
            db = dbf.newDocumentBuilder();

    Document dom;

        dom = db.parse("PVS_XML.xml");

    Element docEle = dom.getDocumentElement();

    NodeList nl = docEle.getElementsByTagName("item");
    System.out.println(((Node) nl).getNodeValue());

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    return null;
}

Error Message:

java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.DeepNodeListImpl cannot be cast to org.w3c.dom.Node
at de.sidion.pvsng.pages.InputPage.readXML(InputPage.java:222)
at de.sidion.pvsng.pages.InputPage.init(InputPage.java:255)
at de.sidion.pvsng.pages.InputPage.<init>(InputPage.java:183)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  • 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-07T02:58:32+00:00Added an answer on June 7, 2026 at 2:58 am

    You cant cast a node list to a node. Get the first element of the list if that is what you want

    NodeList nl = docEle.getElementsByTagName("item");
    ...
    ((Node) nl).getNodeValue() <-- this
    

    if you really want that, either go through the list or get an element of the list:

    for(Node n : nl)
        System.out.println(n.getNodeValue());
    

    EDIT

    My mistake, it is not itterable, try to do it by size:

    for(int i=0; i < nl.getLength(); i++)
    {
       Node childNode = nl.item(i);
       System.out.println(childnode.getNodeValue());
    }
    

    However, I suspect this is still not what you want to do, as what you are getting are elements, and elements do not have values, they have text nodes that have values. Which means you need the child node (the text node). So you probably want something like

    for(int i=0; i<nodeList.getLength(); i++)
    {
       Element childElement = (Element)nodeList.item(i);
       NodeList innernodes = childElement.getChildNodes();
    
       System.out.println(innernodes.item(0).getNodeValue());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read tutorials about how to populate an entire Drop down list with
I have this to populate a drop down list in an ASP.NET MVC view.
If you populate a drop down list of possible values, you only want the
I want to populate a drop down list with values from database. <?php require
I want to populate my drop down list with dynamic values but the list
I want to populate a drop down menu with a column from a MySQL
I want to populate a table, defined in layout xml file through the programmatic
Want to populate dynamically combobox-listbox-drop-down using javascript. var table = document.createElement(table); var select =
I have created and html form which have a drop down list. This drop
I am have three drop down list : Country , State and City. I

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.