Sunday, April 17, 2005

XML Processing

An XML file could be processed by the default Handler, called the even driven programming, i,e
during parsing when we come across start and end elements we hit upon start and end elements
elements and to display the text we use the characters.

Now we are using the DOM,
http://www.w3schools.com/dom/dom_intro.asp

Some points of interest:
1. Objective of DOM has been to provide a standard programming interface to a wide variety applications.
2. With XML DOM one can create an XML document, navigate its structure and add, modify or delete its elements.
3. DOM represents a tree view of the XMl document

4.
Node Type Example
Document type <!DOCTYPE food SYSTEM "food.dtd">
Processing instruction <?xml version="1.0"?>
Element <drink type="beer">Carlsberg</drink>
Attribute type="beer"
Text Carlsberg

5.

One of the first things many programmers want to know is how to read an XML file and generate a DOM Document object from it. Use the DOMEcho example to learn how to do this in three steps. The important lines are:

        // Step 1: create a DocumentBuilderFactory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

// Step 2: create a DocumentBuilder
DocumentBuilder db = dbf.newDocumentBuilder();

// Step 3: parse the input file to get a Document object
Document doc = db.parse(new File(filename));
More on this

No comments: