Sunday, September 28, 2014

How to Use Xerces in Eclipse

Instructions

    1

    Open the Eclipse software and open the Java project you want to use to parse the XML file. Double-click the .java source code file in the left panel to open the code in the editor.

    2

    Instantiate the class and open the XML file. The class loads the XML into a handler so you can edit or display the information. The following code loads the file customer.xml into the parser, but replace this file with your own:

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    xml= db.parse("customer.xml");

    3

    Display the node list. For instance, the following code displays the employee's first and last name to the user:

    Element elements = xml.getDocumentElement();
    NodeList nodes = elements.getElementsByTagName("customer");
    System.out.println((Element)nodes.item('FirstName') + " " + (Element)nodes.item('LastName') );



No comments:

Post a Comment