AutoitMike Posted April 7, 2022 Share Posted April 7, 2022 I am attempting to copy a child node and all its children below a parent node and append the copy to the same parent. The method to select either of the two child node would then be "SelectSingleNode//Parent/Child [0]" for the first child [1] for the second child. I know that node last and node fist would work here but I plan to create many child nodes once I learn this step. Example I am attempting to change this: <template version="5"> <genInfo> <GA> <GASM> <GASMT>Text</GASMT> </GASM> <GASM/> </GA> </genInfo> </template> Into this: <template version="5"> <genInfo> <GA> <GASM> <GASMT>Text</GASMT> </GASM> <GASM/> </GA> </genInfo> <genInfo> <GA> <GASM> <GASMT>Text</GASMT> </GASM> <GASM/> </GA> </genInfo> </template> The following code produces no error but does nothing: Local $oXML = ObjCreate("Microsoft.XMLDOM") ;For all XML fie operations $oXML.load("C:\Utilities\Temp\CloneRPT.hr4") $oNodeChild = $oXML.SelectSingleNode('//template/genInfo') $oNodeParemt = $oXML.SelectSingleNode('//template') $oNodeParemt.appendchild($oNodeChild) $oXML.Save("C:\Utilities\Temp\CloneRPT.hr4") Thanks Link to comment Share on other sites More sharing options...
Nine Posted April 7, 2022 Share Posted April 7, 2022 Try this instead : Local $oXML = ObjCreate("Microsoft.XMLDOM") ;For all XML fie operations $oXML.load("CloneRPT.xml") $oNodeChild = $oXML.SelectSingleNode('//template/genInfo') ConsoleWrite(IsObj($oNodeChild) & @CRLF) $oNodeParent = $oXML.SelectSingleNode('//template') ConsoleWrite(IsObj($oNodeParent) & @CRLF) $oNewNode = $oNodeChild.cloneNode(True) $oNodeParent.appendchild($oNewNode) ConsoleWrite($oNodeParent.xml & @CRLF) You need to create a new object if you want the appendChild to be successful... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
AutoitMike Posted April 8, 2022 Author Share Posted April 8, 2022 (edited) Nine, The child node /genInfo got copied and added to //template, but none of its child nodes or its sibilings got copied / cloned. I thought that the "True" statement was supposed to do this. Edited April 8, 2022 by AutoitMike Link to comment Share on other sites More sharing options...
Nine Posted April 8, 2022 Share Posted April 8, 2022 (edited) It did for me, of course, otherwise I wouldn't have proposed it. I don't know what is wrong with your setup, very strange... Edited March 31, 2023 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
AutoitMike Posted April 9, 2022 Author Share Posted April 9, 2022 I have attached the test file I am using. I thought that just a snippet of the file would work. Maybe thats the problem. Curious to see if you have the same issue. Thanks CloneRPT.hr4 Link to comment Share on other sites More sharing options...
Nine Posted April 9, 2022 Share Posted April 9, 2022 (edited) Still works for me using : $oNodeChild = $oXML.SelectSingleNode('/Report/template/genInfo') Edited March 31, 2023 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
AutoitMike Posted April 9, 2022 Author Share Posted April 9, 2022 NINE, The word TRUE has to be in quotes!! $oNewNode = $oNodeChild.cloneNode('True') OYE! Link to comment Share on other sites More sharing options...
Nine Posted April 9, 2022 Share Posted April 9, 2022 (edited) That is kind of strange. Based on MSDN : Quote Boolean. A flag that indicates whether to recursively clone all nodes that are descendants of this node. If True, creates a clone of the complete tree below this node. If False, clones this node and its attributes only. Seem to be working, with and without quotes on me, even with simple number 0 and 1. Wonder why it is not working for you (without). What is your setup ? Anyway, most important, you found a way to make it work... Edited April 9, 2022 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now