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?