There are
APIs for reading an XML file and displaying them. There are certain
packages that you have to import before you do such a program. The following
is a simple listing template that gives you information on how to create
a document object and then load the XML file in it to process it.
_______________________________________________
import
org.w3c.dom.Document;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
DocumentBuilderFactory
dbfact = DocumentBuilderFactory.newInstance();
DocumentBuilder dbuild = dbfact.newDocumentBuilder();
Document dc = dbuild.parse (new File("xml_file.xml"));
. . .
. . .
doc.getDocumentElement().getNodeName());
NodeList nlist = dc.getElementsByTagName("ele_name");
. . .
. . .
The import
statements on the top gives you access to the classes and the methods
that are used in reading an XML file. To create a document object a
DocumentBuilderFactory object is first created and then a DocumentBuilder
object is created.
With this
DocumentBuilder you can create a Document object and load it with the
XML file you need to process. Then a node list is created and the elements
are loaded in it. This node list is looped by using a 'for' loop and
worked upon.