Hi all,
I've got a huge xml file I want to edit automatically. Over 10 million rows. First I used a for-next loop with FileReadLine, that took ages... of course... Then I tried reading the file to a array, editing the array by replacing certain values and then wrote the array back to a xml file. That worked. Much faster then editing the xml file itself.
#include <File.au3>
#include <Array.au3>
$filename = "OUTPUT_OPDRACHTEN_20120411_221538.xml"
Local $aArray
ConsoleWrite("Reading file..." & @LF)
_FileReadToArray($filename, $aArray)
ConsoleWrite("Reading file... Ready!" & @LF)
$lines = UBound($aArray)
$count = 0
ConsoleWrite("Changing..." & @LF)
For $i = 0 To $lines - 1
If StringInStr($aArray[$i], "<BC_INCASSO>") > 0 Then
$aArray[$i] = "<BC_INCASSO xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:nil=""true""/>"
$count = $count + 1
;ConsoleWrite($i & @LF)
EndIf
If StringInStr($aArray[$i], "<OS_OMA_ONDW_OMA>Wijziging</OS_OMA_ONDW_OMA>") > 0 Then
$aArray[$i] = "<OS_OMA_ONDW_OMA>Verlenging</OS_OMA_ONDW_OMA>"
EndIf
Next
ConsoleWrite("Changing... Ready!" & @LF)
ConsoleWrite("Writing file" & @LF)
$new = FileOpen("new.xml", 129)
For $i = 1 To $lines - 1
FileWriteLine($new, $aArray[$i])
Next
FileClose($new)
ConsoleWrite("Writing file... Ready!" & @LF)
ConsoleWrite($count & @LF)
But now, the next step.... I would like to insert a few rows of code in certain places of the array, but that takes ages again. I guess that's because when I add a new value (_ArrayInsert) on let's say index 5 and it's a array with 10.000.000 values, it has to re-index all values below that new value.
If StringInStr($aArray[$i], "") > 0 Then
$aArray[$i] = "ID1"
_ArrayInsert($aArray,$i+2,"")
_ArrayInsert($aArray,$i+3,"ID2")
_ArrayInsert($aArray,$i+4,"")
ConsoleWrite($i & @LF)
EndIf
Does anybody has a idea how I can do this reasonably fast ?
Greetings.