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

public class Replacenode {

    public static void main(String[] args) throws Exception {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        Document doc = factory.newDocumentBuilder().parse(new File("C:\\Document4.xml"));
        new Replacenode().replacePerson(doc);
    }

    public void replacePerson(Document doc) {

        Element root = doc.getDocumentElement();

        System.out.println("Node before replacing is :" +
                root.getFirstChild().getFirstChild().getNodeName());

        Node fchild = root.getFirstChild();
                //finds the next child of the fchild
        Node schild = fchild.getNextSibling();
        
        //Replaces the fchild with schild    
        root.replaceChild(schild, fchild);

        System.out.println("Node after replacing name is:" +
                root.getFirstChild().getNodeName());

    }
}