Terenz Posted February 13, 2014 Share Posted February 13, 2014 (edited) Hello again, I need to save a variable with this scheme: <fin> ; starting value <aa>aaa</aa> <aa>bbb</aa> <aa>ccc</aa> <aa>ddd</aa> </fin> ; finish value Now the first problem, i don't know if the aaa bbb ccc ddd are always in a row of four, can be also: <fin> ; starting value <aa>aaa</aa> <aa>bbb</aa> </fin> ; finish value Or three or only one...Now the second problem, the scheme not starting always with <fin> but every two "row" with <fin = test> <fin> ; starting value <aa>aaa</aa> <aa>bbb</aa> </fin> ; finish value <fin = test> ; starting value with test <aa>aaa</aa> <aa>bbb</aa> </fin> ; finish value <fin> ; normal starting value <aa>aaa</aa> <aa>bbb</aa> </fin> ; finish value <fin = test> ; starting value with test <aa>aaa</aa> <aa>bbb</aa> </fin> ; finish value This is my starting attempt: local $aArray[8] = ["aaa","bbb","ccc","ddd","eee","fff","ggg","hhh"] Local $End = '<fin>' & @CRLF For $x = 0 To UBound($aArray) -1 $End &= '<aa>' & $aArray[$x] & '</aa>' & @CRLF If $x = 3 then $End &= '</fin>' & @CRLF & '<fin = test>' & @CRLF Next $End &= '</fin>' MsgBox(0,0,$End) Thanks Edited February 13, 2014 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
JohnOne Posted February 13, 2014 Share Posted February 13, 2014 Don't understand question. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Terenz Posted February 13, 2014 Author Share Posted February 13, 2014 (edited) LOL I have an array with an indefinite number of item, example 8 I need to separate this element in a "group", example group of 4 items: <fin> ; starting value <aa>aaa</aa> ; item 1 <aa>bbb</aa> ; item 2 <aa>ccc</aa> ;item 3 <aa>ddd</aa> ;item 4 </fin> ; finish value Every two "group" instead of starting with <fin> ( like the first ) i need to start with <fin = test> <fin> ; starting value <aa>aaa</aa> ; item 1 <aa>bbb</aa> ; item 2 <aa>ccc</aa> ;item 3 <aa>ddd</aa> ;item 4 </fin> ; finish value <fin = test> ; starting value this time is changed <aa>eee</aa> ; item 5 <aa>fff</aa> ; item 6 <aa>ggg</aa> ;item 7 <aa>hhh</aa> ;item 8 </fin> ; finish value Is more clear now? Edited February 13, 2014 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
FireFox Posted February 13, 2014 Share Posted February 13, 2014 Is more clear now?Nope.You posted the desired results, but you didn't give an example.It's not enough detailled.Br, FireFox. Link to comment Share on other sites More sharing options...
JohnOne Posted February 13, 2014 Share Posted February 13, 2014 ?? local $aArray[16] = ["aaa","bbb","ccc","ddd","eee","fff","ggg","hhh","aaa","bbb","ccc","ddd","eee","fff","ggg","hhh"] Local $End = '<fin>' & @CRLF For $x = 0 To UBound($aArray) -1 $End &= '<aa>' & $aArray[$x] & '</aa>' & @CRLF If Not Mod($x,2) then $End &= '</fin>' & @CRLF & '<fin = test>' & @CRLF Next $End &= '</fin>' MsgBox(0,0,$End) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Terenz Posted February 13, 2014 Author Share Posted February 13, 2014 (edited) @Firefox Sorry but an example of what? @JohnOne no, your result is: <fin> <aa>aaa</aa> </fin> <fin = test> <aa>bbb</aa> <aa>ccc</aa> </fin> <fin = test> <aa>ddd</aa> <aa>eee</aa> </fin> The expected result is: <fin> <aa>aaa</aa> <aa>bbb</aa> <aa>ccc</aa> <aa>ddd</aa> </fin> <fin = test> <aa>eee</aa> <aa>fff</aa> <aa>ggg</aa> <aa>hhh</aa> </fin> <fin> <aa>iii</aa> <aa>jjj</aa> <aa>kkk</aa> <aa>lll</aa> </fin> <fin = test> <aa>mmm</aa> <aa>nnn</aa> <aa>ooo</aa> <aa>ppp</aa> </fin> and so on Edited February 13, 2014 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
FireFox Posted February 13, 2014 Share Posted February 13, 2014 Local $aArray[16] = ["aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk", "lll", "mmm", "nnn", "ooo", "ppp"] Local $End = '<fin>' & @LF Local Const $split = 4 For $x = 0 To UBound($aArray) - 1 $End &= '<aa>' & $aArray[$x] & '</aa>' & @LF If Mod($x +1, $split) = 0 Then $End &= '</fin>' & (($x < UBound($aArray) - 2) ? @LF & '<fin = test>' & @LF : '') Next ConsoleWrite($End & @LF) Link to comment Share on other sites More sharing options...
Terenz Posted February 13, 2014 Author Share Posted February 13, 2014 (edited) It require the last version of autoit, i'll download and if i have some problem i'll let you know, thanks Edited February 13, 2014 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
FireFox Posted February 13, 2014 Share Posted February 13, 2014 Or use the _Iif function.#include <Misc.au3> Local $aArray[16] = ["aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk", "lll", "mmm", "nnn", "ooo", "ppp"] Local $End = '<fin>' & @LF Local Const $split = 4 For $x = 0 To UBound($aArray) - 1 $End &= '<aa>' & $aArray[$x] & '</aa>' & @LF If Mod($x + 1, $split) = 0 Then $End &= '</fin>' & _Iif(($x < UBound($aArray) - 2), @LF & '<fin = test>' & @LF, '') Next ConsoleWrite($End & @LF) Link to comment Share on other sites More sharing options...
jdelaney Posted February 13, 2014 Share Posted February 13, 2014 (edited) I'm still not getting the point of constructing this sudo-XML structure. You create it, and then what, do you need to parse it up to deconstruct it again? If that's the case, I'd suggest valid XML, and xmldom...or an ini file. xml sample (with some edits to make valid structure): $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.preserveWhiteSpace = True $oXML.loadXML('<?xml version="1.0" encoding="utf-8"?><fins/>' & @CRLF) Local $aArray[14] = ["aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk", "lll", "mmm", "nnn"] $oRoot = $oXML.selectSingleNode("//fins") $bIsTest = False $oFin = "" For $i = 0 To UBound($aArray)-1 If IsInt($i/4) Then If IsObj($oFin) Then $oRoot.appendChild($oFin) $oFin = "" EndIf $oFin = $oXML.createElement("fin") If $bIsTest Then $oFin.setAttribute("key","test") EndIf $bIsTest = Not $bIsTest EndIf $oAA = $oXML.createElement("aa") $oAA.text = $aArray[$i] $oFin.appendChild($oAA) Next If IsObj($oFin) Then $oRoot.appendChild($oFin) For $oChild In $oRoot.childNodes ConsoleWrite(StringRegExpReplace($oChild.xml,"><",">" & @CRLF & "<") & @CRLF) Next output: <fin> <aa>aaa</aa> <aa>bbb</aa> <aa>ccc</aa> <aa>ddd</aa> </fin> <fin key="test"> <aa>eee</aa> <aa>fff</aa> <aa>ggg</aa> <aa>hhh</aa> </fin> <fin> <aa>iii</aa> <aa>jjj</aa> <aa>kkk</aa> <aa>lll</aa> </fin> <fin key="test"> <aa>mmm</aa> <aa>nnn</aa> </fin> reading back the data would be a simple dom crawl. Edited February 13, 2014 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