From: Moisei R. <mra...@il...> - 2002-10-14 13:36:14
|
Hi, I've used "::dom::document importNode" function in the same case, check whether this function exists in your dom implementation. Pay attention the deep option is boolean and means recursive/not recusrsive import but not the real deep level. the sample is like following: set xmlStr1 {<DOC1> <E11 a1="1"/> <E12 a2="2"/></DOC1>} set xmlStr2 {<DOC2> <E21 a1="1"/> <E22 a2="2"/></DOC2>} set doc1 [::dom::DOMImplementation parse $xmlStr1 -parser expat] set doc2 [::dom::DOMImplementation parse $xmlStr2 -parser expat] set origNode [::dom::document cget $doc2 -documentElement] set importedNode [::dom::document importNode $doc1 $origNode -deep 1] ;# deep is boolean set targetNode [::dom::document cget $doc1 -documentElement] ::dom::DOMImplementation destroy $doc2 dom::node appendChild $targetNode $importedNode ::dom::DOMImplementation serialize $doc1 and here is with the results: % set xmlStr1 {<DOC1> <E11 a1="1"/> <E12 a2="2"/></DOC1>} <DOC1> <E11 a1="1"/> <E12 a2="2"/></DOC1> % set xmlStr2 {<DOC2> <E21 a1="1"/> <E22 a2="2"/></DOC2>} <DOC2> <E21 a1="1"/> <E22 a2="2"/></DOC2> % set doc1 [::dom::DOMImplementation parse $xmlStr1 -parser expat] node1 % set doc2 [::dom::DOMImplementation parse $xmlStr2 -parser expat] node7 % set origNode [::dom::document cget $doc2 -documentElement] node8 % set importedNode [::dom::document importNode $doc1 $origNode -deep 1] node13 % set targetNode [::dom::document cget $doc1 -documentElement] node2 % ::dom::DOMImplementation destroy $doc2 ;# the imported node exists even after the original doc is destroyed % dom::node appendChild $targetNode $importedNode % ::dom::DOMImplementation serialize $doc1 <?xml version='1.0'?> <!DOCTYPE DOC1> <DOC1> <E11 a1='1'/> <E12 a2='2'/><DOC2> <E21 a1='1'/> <E22 a2 ='2'/></DOC2></DOC1> % Enjoy, Best Regards, Moisei Derek Fountain <fo...@hu...> To: tcl...@li... Sent by: cc: tcl...@li...urc Subject: [Tclxml-users] Move node from one tree to another eforge.net 10/14/2002 03:09 PM I have parsed two XML documents into 2 trees and I want to move a node (and its children) from a point in one tree to a point in the other. Cutting the required node out with "dom::node removeChild" is easy, but when I want to place it in it's new tree I get an error saying "new node must be in the same document". Well, OK, I was kind of expecting that. What do I need to do to make this cut/paste work as required? -- 2:05pm up 6:42, 1 user, load average: 0.00, 0.07, 0.07 ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Tclxml-users mailing list Tcl...@li... https://lists.sourceforge.net/lists/listinfo/tclxml-users |