/*
 * Test Case
 */
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;


public class Test {

	DocumentBuilderFactory dbf;
	DocumentBuilder db;

	/**
	 * Runs the test case.
	 */
	public void runTest1() {
		System.out.println("Running test..." + "\n");
		try {
			
			Document doc = (Document) db.parse("test.xml");
			
			NodeList itemList;
	        Element pElem;
	        Text text1;
	     
	        itemList = doc.getElementsByTagName("p");
	        pElem = (Element) itemList.item(0);
	        text1 = (Text)pElem.getFirstChild();
	        
	        System.out.println("Text to be Removed: " + text1.getWholeText() + "\n");
	        text1.replaceWholeText("cat");
	        System.out.println("getWholeText on text1 after replaceWholeText: " + text1.getWholeText());
	        
	        Node emptyElem = text1.getNextSibling();
	        Node n = emptyElem.getNextSibling();
	        System.out.println("\n" + n.getNodeValue());
	
	        
		} catch (Exception e) {
			System.err.println("Test 1 Failed:" + e.getMessage());
			e.printStackTrace();
		}
	}

	

	public void init() {
		try {
			dbf = DocumentBuilderFactory.newInstance();
			dbf.setNamespaceAware(true);
			dbf.setExpandEntityReferences(false);
			db = dbf.newDocumentBuilder();
		} catch (Exception e) {
			System.out.println("Initialization Failed:" + e.getMessage());
		}
	}

	/**
	 * @param args command line arguments
	 */
	public static void main(String[] args) {
		Test t = new Test();
		t.init();
		
		t.runTest1();
	}


}

