package gtest;

import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.*;
import org.xml.sax.*;

/**
 * A class for testing the JAXP classes
 */

public class XMLTest {
    public String HelloWorld( String message, int count ){
        return "";
    }

    /**
     * create a dom parser and ouput some stuff
     *
     */
    protected void dom(){
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            File file = new File( "C:\\java\\sax2\\javaxml\\Ch03\\contents.xml" );
            Document doc = builder.parse(file);
            System.out.println(doc.getNodeName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * create a sax parser and output some stuff
     *
     */
    protected void sax(){
        try {
            SAXParserFactory factory = SAXParserFactory.newInstance();
            SAXParser parser = factory.newSAXParser();
            File file = new File( "C:\\java\\sax2\\javaxml\\Ch03\\contents.xml" );
            parser.parse( file, new HandlerBase(){
                public void startElement(String name, AttributeList attributes){
                    System.out.println( name );
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Default constructor
     *
     */
    public XMLTest() {
        sax();
    }

    /**
     * A test main menthod
     *
     * @param args Lets set some comments
     */
    public static void main(String[] args){
        XMLTest test = new XMLTest();
    }
}
1