package lecture.sample.xml.dom;

import java.io.File;
import java.io.IOException;

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

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

/**
 * @author default
 *
 * XML Parsing using the Document Object Model (DOM)
 */
public class DOMParsingSample1 {
	
	/**
	 * create new instance of DOMParsingSample1
	 */
	public DOMParsingSample1(){
		try{
			// construct a vendor neutral document builder through the JAXP API
			DocumentBuilder xBuilder = 
				DocumentBuilderFactory.newInstance().newDocumentBuilder();
			
			// parse the document into a Document object
			Document xDocument = xBuilder.parse(new File("test.xml"));
			
			// the document is ready to be manipulated 			
			NodeList xNodes = xDocument.getDocumentElement().getChildNodes();
			
			
		       
			
		} catch (IOException xEx){
			// error reading the file	
		} catch (SAXException xEx){
			// error parsing the document
		} catch (ParserConfigurationException xEx){
			// error parsing the document
		}
	}
	

	public static void main(String[] args) {
		new DOMParsingSample1();
	}
}