[HELP] Create a DOM using a node from another node

Discussion in 'Java' started by yio@free.fr, Jul 16, 2003.

  1. Guest

    Hi,

    I'm posting an answer for people looking about the same thing.

    private Document createNewDOM(Document srcDocument) {

    try {
    //Create the resulting DOM
    Document resultDocument =
    DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();

    //import an element (here, it is the root element) from first DOM
    DocumentFragment df = srcDocument.createDocumentFragment();
    documentFragment.appendChild(srcDocument.getDocumentElement());

    //Create the Node to append to the new DOM
    Node importNode = resultDocument.importNode(documentFragment,
    true);

    resultDocument.appendChild(importNode);
    }

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

    finally {
    return resultDocument;
    }


    hope that help!!
    Bye
    Lionel
     
    , Jul 16, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,470
  2. Matt
    Replies:
    0
    Views:
    613
  3. Eddy C
    Replies:
    6
    Views:
    6,432
    Eddy C
    Oct 18, 2005
  4. Tjerk Wolterink
    Replies:
    2
    Views:
    1,440
    Dimitre Novatchev
    Aug 24, 2006
  5. Joshua Muheim
    Replies:
    2
    Views:
    133
    Aaron Patterson
    Oct 13, 2009
Loading...

Share This Page