Read the XML file on website

Posted on 2006-05-22
Last Modified: 2010-03-31
Hi Expert,
I have to download the information form the web site XML file and populate the ComboBox with these information. I would like if u could provide me with examples that can help me to do so -- regards
The information in the web site, as an example, like this :

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <FDStations>
- <FDStation>
- <FDStation>

I have to populate Combo Box with the Name above.

Question by:westerntour
    LVL 86

    Accepted Solution

    1. Get the root element of the Document (see link on the following page too)

    2. Get the 'Name' elements

    3. Construct a DefaultComboBoxModel with the resulting list to create your combo

    LVL 10

    Assisted Solution

    this code is a genric parser used to parse an XML and return all the elements with its values.
    Once you have got the XML from the inter net. you can pass it to this parser and get the required information.


    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;

    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;

    public class GenricParser {
          public static void main(String[] args) throws
                ParserConfigurationException, SAXException, IOException{
                DocumentBuilderFactory factory =
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document document = builder.parse(new File("result.xml"));
                Element root = document.getDocumentElement();
                NodeList nList = root.getChildNodes();

                for(int i=0;i<nList.getLength();i++){
                      Node node = nList.item(i);
                      if(node.getNodeType() == Node.ELEMENT_NODE){
                            NodeList nList1 = node.getChildNodes();
                            int count=0;
                            for(int j=0;j<nList1.getLength();j++){
                            Node node1 = nList1.item(j);
                                        }//End of IF
                                  }//End of inner For(j)
                            }//End of outer IF
                      }//End of Outer For(i)


    Instead of the file. you can give the String also to the parser


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Title # Comments Views Activity
    what is spring 3 35
    nested class vs inner class 5 36
    scoresIncreasing challenge 10 47
    strCount chalenge 3 34
    Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now