Jump to content

which method would be quicker?


cuShane
 Share

Recommended Posts

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?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...