cuShane Posted February 4, 2009 Posted February 4, 2009 I am trying to figure out which way it would be quicker to add a tag to an xml file: using the XML DOM wrapper or using _replacestringinfile. Whenever a node in the xml file has an artist tag containing an artist that is listed in $artistarray, I want to add a new Fanart tag. The xml file is huge (several thousand nodes each containing around a dozen children). $artistarray contains several hundred entries. Method 1 (XML DOM wrapper): CODELocal $MusicLibrary = "test.xml" ConsoleWrite($MusicLibrary) Local $oML = _XMLFileOpen ($MusicLibrary) If @error Then MsgBox(0, "Error", "There was an error opening the file.") Exit EndIf For $k = 1 to UBound($artistsarray)-1 $artist = $artistsarray[$k] Local $sRet = _XMLSelectNodes ("//Music/*") For $x = 1 To $sRet[0] If $sRet[$x] = "Item" Then If _RetFirst(_XMLGetChildText ("Music/*[" & $x & "]/artist")) = $artist Then _XMLCreateChildNode ( "Music/*[" & $x & "]", "Fanart", "test1") EndIf EndIf Next Next Method 2 (_replacestringinfile): CODEFor $k = 1 to UBound($artistsarray)-1 $artist = $artistsarray[$k] _ReplaceStringInFile("C:\test.xml", "<artist>" & $artist & "</artist>", "<artist>" & $artist & "</artist>" & @CRLF & "<Fanart>test1</Fanart>") Next Does anyone have any experience that would lead you to believe that one way would be quicker/more efficient than the other?
BrettF Posted February 4, 2009 Posted February 4, 2009 Do your own testing using TimerInit/TimerDiff etc... Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
cuShane Posted February 5, 2009 Author Posted February 5, 2009 Thanks for the help. FYI - the replacestringinfile method was MUCH faster.
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