Question Searching through multiple XML files for duplicate entry?

cooktehbacon

New member
Joined
Dec 8, 2009
Messages
1
Programming Experience
1-3
Basically I'm making a web service which allows users to enter a playlist (text only). But i also want to rate each song with a +1 timer if it appears in more than 1 playlist.

Now i know xpath is used if all the playlists are in the same xml file but Ive made it to so each playlist entered is in its own seperate xml file and i have no clue how to search through multiple files.

So how would i make a function that loops through all the files in a specific folder and gives the song a rating on how many playlists it has appeared in and enter this score as an xml node(<SongRating></SongRating>?

So far i made 2 functions with the help of my lecturer

First 1 doesnt run at all

VB.NET:
<WebMethod()> _
    Public Function DocumentContainsTitle(ByVal doc As String, ByVal title As String) As Boolean
        Dim xmlDoc As New XmlDocument
        xmlDoc.Load(doc)
        Dim elem As XmlElement = xmlDoc.DocumentElement.SelectSingleNode("Playlist[Song ID=’" & title & "’]")
        If elem IsNot Nothing Then
            Return True
        Else
            Return "failsauce"
        End If

    End Function

Second one comes back as 0

VB.NET:
<WebMethod()> _
    Public Function CountDocsThatContainTitle(ByVal title As String) As Integer
        Dim files() As String = Directory.GetFiles(Server.MapPath("~/App_Data"), ".xml")
        Dim file As String
        Dim titleCount As Integer = 0

        For Each file In files
            If DocumentContainsTitle(file, title) Then
                titleCount += 1
            End If
        Next
        Return titleCount
    End Function
 
Last edited:
Back
Top