amakrkr Posted March 27, 2013 Share Posted March 27, 2013 (edited) Hello, i am reopening thread about my problem since it eveloved quite a bit since i opended my previous thread. Ok we have same XML files as before: This one is "Base" XML file ... we will insert and delete nodes from here: <Targets AGENT_TOKEN="fbb03f77162ce70f15122343dd6b16eb8de29b6c"> <Target TYPE="oracle_emd" NAME="localhost:3938"/> <Target TYPE="host" NAME="localhost"/> <Target TYPE="oracle_database" NAME="word"> <Property NAME="MachineName" VALUE="localhost"/> <Property NAME="Port" VALUE="1521"/> <Property NAME="SID" VALUE="word"/> <Property NAME="OracleHome" VALUE="c:\app\product\11.2.0\dbhome_2"/> <Property NAME="UserName" VALUE="821212d" ENCRYPTED="TRUE"/> <Property NAME="password" VALUE="061b022" ENCRYPTED="TRUE"/> </Target> <Target TYPE="oracle_listener" NAME="LISTENER_localhost"> <Property NAME="Machine" VALUE="localhost"/> <Property NAME="LsnrName" VALUE="LISTENER"/> <Property NAME="Port" VALUE="1521"/> <Property NAME="OracleHome" VALUE="c:\app\product\11.2.0\dbhome_2"/> <Property NAME="ListenerOraDir" VALUE="c:\app\product\11.2.0\dbhome_2\network\admin"/> </Target> <Att08> </Att08> </Targets> and this one is user-formed XML we will insert nodes from here to "base" XML: <Property NAME="Inserted text 1" VALUE="11"/> <Property NAME="Inserted text 2" VALUE="11"/> <Property NAME="Inserted text 3" VALUE="11"/> <Property NAME="Inserted text 4" VALUE="11"/> This is my script so far it opens base xml file deletes node <Att08> from it if its there and creates "empty" node <Att08></Att08> #include <File.au3> #include<_XMLDomWrapper.au3> #include<Array.au3> $formed_xml = @ScriptDir & "\" & "created.xml" $origin_xml = @ScriptDir & "\" & "original.xml" _XMLFileOpen($origin_xml) $re = _XMLGetChildNodes("/Targets/Att08") _XMLDeleteNode("/Targets/Att08") _XMLCreateChildNode("/Targets","Att08") _XMLCreateChildWAttr("/Targets/Att08","r","","") ; tested insert of a node Now here lies the problem. After i delete the node i should open user formed XML and insert everything thats in that file into <Att08> node in base XML. Here i am lost. I do not know how to do that. If i load user-formed XML into a array i have no idea how to read values from it and cunstruct a for loop to insert everything thats in that array. Please i would really require some herelp here. Thank you ! Edited March 27, 2013 by amakrkr Link to comment Share on other sites More sharing options...
jdelaney Posted March 27, 2013 Share Posted March 27, 2013 (edited) Create, and add nodes to xml:http://www.w3schools.com/dom/dom_nodes_create.aspI'm unfamiliar with the xmldomwrapper.au3, but I would just use the methods/properties avaiable to me. (link shows how to create, and add attributes as well) Edited March 27, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
amakrkr Posted March 27, 2013 Author Share Posted March 27, 2013 (edited) Hi, thank you for your input i will try to learn and will post back. I checked the ink you provided but ... thats java isnt it? What does it have to do with autoit? Edited March 27, 2013 by amakrkr Link to comment Share on other sites More sharing options...
amakrkr Posted March 28, 2013 Author Share Posted March 28, 2013 expandcollapse popup#include <File.au3> #include<_XMLDomWrapper.au3> #include<Array.au3> $formed_xml = @ScriptDir & "\" & "FORM.xml" $origin_xml = @ScriptDir & "\" & "ORIGINAL.xml" $xml_open_original = _XMLFileOpen($origin_xml) $xml_open_original = _XMLGetChildNodes("/Targets/Att08") $xml_open_original = _XMLDeleteNode("/Targets/Att08") $xml_open_original = _XMLCreateChildNode("/Targets","Att08") $xml_open_original = _XMLCreateChildWAttr("/Targets/Att08","r","","") ; tested insert of a node $formed_xml = _XMLFileOpen($formed_xml) $count_row_data = _XMLGetNodeCount("/Att08/TableA/RowAData") ;132 $count_rows = _XMLGetChildNodes("/Att08/TableA/RowAData") $count_NAME = _XMLGetChildNodes("/Att08/TableA/RowAData/NameSurname") $aPriimek = _XMLGetValue("/Att08/TableA/RowAData/NameSurname") $aTaxNo = _XMLGetValue("/Att08/TableA/RowAData/TaxNo") $aReliefType = _XMLGetValue("/Att08/TableA/RowAData/ReliefType") $aEmploymentDate = _XMLGetValue("/Att08/TableA/RowAData/EmploymentDate") $aSalary = _XMLGetValue("/Att08/TableA/RowAData/Salary") $aFifthyPerSalary = _XMLGetValue("/Att08/TableA/RowAData/FifthyPerSalary") $aSeventyPerSalary = _XMLGetValue("/Att08/TableA/RowAData/SeventyPerSalary") _XMLFileOpen($origin_xml) _XMLCreateChildNode("/Targets/Att08","TableA") for $i=1 to $count_row_data _XMLCreateChildNode("/Targets/Att08/TableA","RowAData") for $X=$I to $count_rows IF $count_NAME = 1 then ExitLoop else _XMLCreateChildNode("/Targets/Att08/TableA/RowAData","NameSurname",$aSurname[$i]) _XMLCreateChildNode("/Targets/Att08/TableA/RowAData","TaxNo",$aTaxNo[$i]) _XMLCreateChildNode("/Targets/Att08/TableA/RowAData","ReliefType",$aReliefType[$i]) _XMLCreateChildNode("/Targets/Att08/TableA/RowAData","EmploymentDate",$aEmploymentDate[$i]) _XMLCreateChildNode("/Targets/Att08/TableA/RowAData","Salary",$aSalary[$i]) _XMLCreateChildNode("/Targets/Att08/TableA/RowAData","FifthyPerSalary",$aFifthyPerSalary[$i]) _XMLCreateChildNode("/Targets/Att08/TableA/RowAData","SeventyPerSalary",$aSeventyPerSalary[$i]) endif Next NEXT This is code i got so far. Problem is still in for loops ... i just can get it to work. As you can see first i delete any existant nodes and then i try to insert new node called TableA ... all good so far. then i hit 1st loop ... i counted how many records i got in it and i create new node RowData in this note there should be 7 child nodes but problem is when i run script all those last chiled nodes are displayed under same node. this is XML where i am inserting into: <Targets AGENT_TOKEN="fbb03f77162ce70f15122343dd6b16eb8de29b6c"> <Target TYPE="oracle_emd" NAME="localhost:3938"/> <Target TYPE="host" NAME="localhost"/> <Target TYPE="oracle_database" NAME="word"> <Property NAME="MachineName" VALUE="localhost"/> <Property NAME="Port" VALUE="1521"/> <Property NAME="SID" VALUE="word"/> <Property NAME="OracleHome" VALUE="c:\app\product\11.2.0\dbhome_2"/> <Property NAME="UserName" VALUE="821212d" ENCRYPTED="TRUE"/> <Property NAME="password" VALUE="061b022" ENCRYPTED="TRUE"/> </Target> <Target TYPE="oracle_listener" NAME="LISTENER_localhost"> <Property NAME="Machine" VALUE="localhost"/> <Property NAME="LsnrName" VALUE="LISTENER"/> <Property NAME="Port" VALUE="1521"/> <Property NAME="OracleHome" VALUE="c:\app\product\11.2.0\dbhome_2"/> <Property NAME="ListenerOraDir" VALUE="c:\app\product\11.2.0\dbhome_2\network\admin"/> </Target> <Att08> </Att08> </Targets> and this is XML from which i am inserting into: <Att08> <TableA> <RowAData> <NameSurname>George</NameSurname> <TaxNo>21334343</TaxNo> <ReliefType>D</ReliefType> <EmploymentDate>1979-06-11T00:00:00</EmploymentDate> <Salary>12331.37</Salary> <FifthyPerSalary>2135.69</FifthyPerSalary> <SeventyPerSalary>0</SeventyPerSalary> </RowAData> <RowAData> <NameSurname>Ally</NameSurname> <TaxNo>8343434343</TaxNo> <ReliefType>D</ReliefType> <EmploymentDate>1976-04-12T00:00:00</EmploymentDate> <Salary>8326.54</Salary> <FifthyPerSalary>4233.27</FifthyPerSalary> <SeventyPerSalary>0</SeventyPerSalary> </RowAData> <RowAData> <NameSurname>Bob</NameSurname> <TaxNo>834343</TaxNo> <ReliefType>F</ReliefType> <EmploymentDate>1985-04-16T00:00:00</EmploymentDate> <Salary>34333.33</Salary> <FifthyPerSalary>0</FifthyPerSalary> <SeventyPerSalary>838.63</SeventyPerSalary> </RowAData> </TableA> </Att08> Link to comment Share on other sites More sharing options...
amakrkr Posted March 28, 2013 Author Share Posted March 28, 2013 really 64 view and not one reply? Link to comment Share on other sites More sharing options...
BrewManNH Posted March 28, 2013 Share Posted March 28, 2013 I'm sure most people look at this and don't know anything about XML files, the number of views is irrelevant to the number of people able to help. amakrkr 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
amakrkr Posted March 28, 2013 Author Share Posted March 28, 2013 (edited) Problem is ... how can i cose tag? I mean 1st for loop goes trought nodes in my formed XML .. it creates 1st child node <RawData> and proceeds to second loop -> there it starts inserting other nodes ... but after 2nd loop is finished it should close tag </RaData> , fall back into 1st loop create new child tag and move to 2nd loop . But i do not know how to acomplished tahat. Edited March 28, 2013 by amakrkr Link to comment Share on other sites More sharing options...
amakrkr Posted March 28, 2013 Author Share Posted March 28, 2013 I'm sure most people look at this and don't know anything about XML files, the number of views is irrelevant to the number of people able to help.Its almost a loop releated problem I remember this comunity a lot more active and responsive on forums. Now i have posted whole code and examples and this is already 3rd thread about same issue i created and ZERO usefull replys. Link to comment Share on other sites More sharing options...
jdelaney Posted March 28, 2013 Share Posted March 28, 2013 (edited) ZERO usefull replys. I gave you a link that shows how to create and append that new node into XML. $stest = '<?xml version="1.0"?><items></items>' $oXML=ObjCreate("Microsoft.XMLDOM") ;~ $stest = @DesktopDir & "\xml2.xml" $oXML.loadxml($stest) $oParent = $oXML.SelectSingleNode("//items") For $i = 0 To 9 $oNewItem = $oXML.createElement("Item" & $i) $oNewItem.text = "SomeValue" & $i $oParent.appendChild($oNewItem) Next ConsoleWrite ( $oXML.xml & @CRLF ) Input: '<?xml version="1.0"?><items></items>' Output: <?xml version="1.0"?> <items><Item0>SomeValue0</Item0><Item1>SomeValue1</Item1><Item2>SomeValue2</Item2><Item3>SomeValue3</Item3><Item4>SomeValue4</Item4><Item5>SomeValue5</Item5><Item6>SomeValue6</Item6><Item7>SomeValue7</Item7><Item8>SomeValue8</Item8><Item9>SomeValue9</Item9></items> Edited March 28, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
amakrkr Posted March 29, 2013 Author Share Posted March 29, 2013 (edited) It is still unclear or maybe my explanation is missleading. What my loop is doing wrong is : when it creats Node <RawData> i insert chield element into it <NameSurname> now it should close element and proceed with opening another Node <RawData> insert element into it close it and so forth. Instead what my loop is doing is creates a node <RawData> inserts child node and closes parent node </RawData> now after i insert another node <RawData> child element goes inserted into previous already closed element and into newly created as well. So its redplicationg values as crazy. Edited March 29, 2013 by amakrkr Link to comment Share on other sites More sharing options...
jdelaney Posted March 29, 2013 Share Posted March 29, 2013 (edited) If you know how to create, and know what's going on durring the append, then you would know how to create xml trees. $stest = '<?xml version="1.0"?><items></items>' $oXML = ObjCreate("Microsoft.XMLDOM") ;~ $stest = @DesktopDir & "\xml2.xml" $iCounter = 0 $oXML.loadxml($stest) $oParent = $oXML.SelectSingleNode("//items") For $i = 0 To 9 $oNewItem = $oXML.createElement("Item" & $i) $oNewItem.setAttribute("Count",$iCounter) ;~ $oNewItem.text = "SomeValue" & $i $oParent.appendChild($oNewItem) $iCounter+=1 For $j = 0 To 5 $oNewChildItem = $oXML.createElement("Child" & $j) $oNewChildItem.setAttribute("Count",$iCounter) ;~ $oNewChildItem.text = "ChildValue" & $j $oNewItem.appendChild($oNewChildItem) $iCounter+=1 For $k = 0 To 2 $oNewGrandChild = $oXML.createElement("GrandChild" & $k) $oNewGrandChild.setAttribute("Count",$iCounter) $oNewGrandChild.text = "GrandChildValue" & $k $oNewChildItem.appendChild($oNewGrandChild) $iCounter+=1 Next Next Next ConsoleWrite($oXML.xml & @CRLF) put output into XML file, and view in IE, you will see the tree...the xml dom logically places in closing nodes Edited March 29, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. 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