-1

I have created a web service using ASP.NET and am now creating a client application to consume it.

The service allows the user to create playlist and add songs etc The lists are stored in a XMl file with the following structure:

<?xml version="1.0" encoding="utf-8"?>
<Playlists>
    <Lists>
        <List ID="3" user="dylan">
            <Track name="Sorry">
                <Artist>Justin Bieber</Artist>
                <Album>Purpose</Album>
                <Genre>Pop</Genre>
            </Track>
            <Track name="Thriller">
                <Artist>Michael Jackson</Artist>
                <Album>Thriller</Album>
                <Genre>Pop</Genre>
            </Track>
            <Track name="Hello">
                <Artist>Adele</Artist>
                <Album>25</Album>
                <Genre>Pop</Genre>
            </Track>
        </List>
    </Lists>
</Playlists>

I am looking to extract the various track names, artist, album and genre and display them in a Windows form List Box.

Currently, my code allows me to select a list. However, rather than display the name, artist, album then genre, the list box displays the following (please ignore the data. in this version, I accidentally added 2 instances of Michael Jackson 'Thriller', I'm not that much of a fan! ;) Also, Thriller in this photo is the Album:

ListBox Output

I cannot seem to be able to select the "name" attribute.

Any help would be much appreciated. I would like to keep the XML structure the same if possible.

I have posted the code I am using in the client app below.

Public Class Form1
    Dim serviceReturn As String
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Dim service As New PlaylistReference.ServiceSoapClient
        Try
            serviceReturn = service.GetPlaylist(TextBox1.Text)
            MessageBox.Show(serviceReturn)
        Catch ex As Exception
            MessageBox.Show("A stock quote for this ticker was not available.")
        End Try
        Dim xmlPlaylist As New Xml.XmlDocument
        xmlPlaylist.LoadXml(serviceReturn)
        Dim xmlSong As Xml.XmlNode
        For Each xmlSong In xmlPlaylist.DocumentElement
            Dim songName As String = xmlPlaylist.LastChild.InnerText
            ListBox1.Items.Add(songName)
        Next
    End Sub
End Class

So all that happens is I enter the name of the playlist into TextBox1 and then the press of the button gets the output above. Please ignore the MessageBox function, this is just for testing purposes.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118

1 Answers1

0

I believe your question can be narrowed down to: I cannot seem to be able to select the "name" attribute.

Attributes are in the Attributes property, i.e. xmlSong.Attributes("name").Value

Jon Davis
  • 6,562
  • 5
  • 43
  • 60