we are trying to append a node of one docuemnt object to another document
object.
we tried to use importNode method, whcih is giving us following run time
error:


  java.lang.NoSuchMethodError: org.w3c.dom.Node: method
getLocalName()Ljava/lang/String; not found

        at org.apache.xerces.dom.DocumentImpl.importNode(DocumentImpl.java,
Compiled Code)

        at
org.apache.xerces.dom.DocumentImpl.importNode(DocumentImpl.java:844)

        at MoveNode.main(MoveNode.java:38)

>  
The code is :


import org.apache.xerces.parsers.DOMParser;
import org.xml.sax.InputSource;
import org.w3c.dom.*;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.apache.xerces.dom.DocumentImpl;
public class MoveNode {          

    public static void main(String[] args) {
        try {
            DOMParser parser = new DOMParser();  

            // Create the first document          
            parser.parse(new InputSource(args[0]));
            DocumentImpl doc1 = (DocumentImpl)parser.getDocument();

            // Create the second document
            parser.parse(new InputSource(args[1]));
            DocumentImpl doc2 = (DocumentImpl)parser.getDocument();

            // Get root of first document
            Element firstRoot = doc1.getDocumentElement();

            // Get Node to move
            Element secondRoot = doc2.getDocumentElement();
                        
                        System.out.println("secondroot = " +
secondRoot.getFirstChild().getNodeValue() );
                        
                        NodeList kids =
secondRoot.getElementsByTagName("role");
                        
                        System.out.println("kids " + kids.getLength());
            Element oneToMove = (Element)kids.item(0);
                        
                        System.out.println("onetomove =" +
oneToMove.getFirstChild().getNodeValue());

            // Add to first document
            Node newOneToMove = doc1.importNode(oneToMove, true);
            firstRoot.appendChild(newOneToMove);

        } catch (Exception e) {
             e.printStackTrace();
        }
    }

}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to