Jump to content
Sign in to follow this  
cuShane

which method would be quicker?

Recommended Posts

cuShane

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):

CODE
Local $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):

CODE
For $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?

Share this post


Link to post
Share on other sites
BrettF
cuShane

Thanks for the help.

FYI - the replacestringinfile method was MUCH faster.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.