
import org.w3c.dom.*;
import org.apache.xerces.dom.*;
import org.apache.xml.serialize.*;

import java.io.UnsupportedEncodingException;
import java.io.IOException;


class DOMCreation1
{
    static final String docNamespace = "http://dummy.namespace.com/myDocument";
    static final String elemNamespace = "http://dummy.namespace.com/myElement";


    public static void main( String[] args )
        throws UnsupportedEncodingException,
               IOException
    {
        DOMImplementation x = DOMImplementationImpl.getDOMImplementation();
        Document doc = x.createDocument( docNamespace, 
                                         "docpref:docName",
                                         null /* doctype */ );
        System.err.println( "doc = " + doc );
        Element rootElem = doc.getDocumentElement();
        System.err.println( "rootElem = " + rootElem );

        Element newElem1 = doc.createElement( "simple" );
        rootElem.appendChild( newElem1 );

        Element newElem2 = 
            doc.createElementNS( elemNamespace, "elempref:prefixed" );
        rootElem.appendChild( newElem2 );
        


        SerializerFactory factoryXHTML =
            SerializerFactory.getSerializerFactory( "xhtml" );
        System.err.println( "factoryXHTML = " + factoryXHTML );

        OutputFormat fmt = new OutputFormat();

        System.err.println( "fmt = " + fmt );
        fmt.setMethod( "xhtml" );
        fmt.setIndent( 2 );
        

        Serializer serializerXHTML =
            factoryXHTML.makeSerializer( System.err, fmt );

        System.err.println( "serializerXHTML = " + serializerXHTML );

        System.err.println();
        serializerXHTML.asDOMSerializer().serialize( doc );
        System.err.println();
        

        
    } // main( String [] )
    

} // class DOMCreation1
