import org.w3c.dom.*;
import org.w3c.dom.ls.DOMWriter;
import org.xml.sax.*;

public class TestClass 
{
    org.apache.xerces.parsers.DOMParser parser;

    public TestClass()
    {
         try {
            parser = new org.apache.xerces.parsers.DOMParser();
            parser.setFeature( "http://xml.org/sax/features/validation", false );
            parser.setFeature( "http://xml.org/sax/features/namespaces", false );
	  }
          catch (Exception e) {
            System.out.println("Exception :" + e);
            System.exit(1);
          }
    }

    static public void setTagName(Node tree, String tagName)
    {
	try {
	  Document doc = tree.getOwnerDocument();
System.out.println(" #### before renameNode");
	  ((org.apache.xerces.dom.DocumentImpl)doc).renameNode(tree, null, tagName);
System.out.println(" #### after renameNode");
	}
	catch(Exception e) {
	  	System.out.println("Exception :" + e);
	}
    }

   static public void print(Element tree)
   {
	DOMWriter domWriter = new org.apache.xml.serialize.DOMWriterImpl(false);
	try {
	  domWriter.writeNode( System.out, tree);
	}
	catch(Exception e) {
	}
	System.out.println("");
    }

    /** 
    * Main program entry point.
    */
    public static void main(String arguments[]) 
    {
    	TestClass rn = new TestClass();
    	
    	//=== create an element with tag name "hello" 
    	Document doc = new org.apache.xerces.dom.DocumentImpl();
	Element tree = doc.createElement("hello");  	
    	
    	TestClass.print(tree);
    	
    	//=== try to change the tag name
    	TestClass.setTagName(tree, "HELLO" );
    	
    	TestClass.print(tree);
    	
	//=== add a child
	Element child = doc.createElement( "bye" );
	tree.appendChild( child );
    	
    	TestClass.print(tree);
    	
    	//=== try to change the tag name of the child
    	TestClass.setTagName( child, "BYE" );
    	
    	TestClass.print(tree);
    }
}

