Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

insertbefore dont work

843834May 24 2007 — edited May 25 2007
i need to insert one node from one document (docDcont) to another document (doc) but this my code don�'t work.
  try {

            // parse the XML as a W3C Document
            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = builder.parse(new File("book1.xml"));
            Document docDcont = builder.parse(new File("book.xml"));
                   

                    	   XPath xpath = XPathFactory.newInstance().newXPath();
                           String expression = "//chapter"; //select the node
                           // obtain the element as a node.
                           
                           Node node = (Node)xpath.evaluate(expression, docDcont, XPathConstants.NODE);  
                               
                           System.out.println("node name: " + node.getNodeName());
                           
                        doc.insertBefore(node, doc.getFirstChild().getNextSibling().getNextSibling());// not correct - error 
                   
        
              
            dump(doc);
can anyone help?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 22 2007
Added on May 24 2007
3 comments
114 views