www.webdeveloper.com
Results 1 to 2 of 2

Thread: Consume xml <media:content> tag

  1. #1
    Join Date
    Jun 2004
    Location
    Kansas City, MO
    Posts
    1,607

    Consume xml <media:content> tag

    Im trying to get the url from a <media:content> tag and i cant figure out how to get it.

    Here is the code im using to bind to a repeater
    Code:
    Dim rssFeed As HttpWebRequest = DirectCast(WebRequest.Create("http://sports.yahoo.com/mlb/rss.xml"), HttpWebRequest)
    Dim rssData As DataSet = New DataSet()
    rssData.ReadXml(rssFeed.GetResponse().GetResponseStream())
       
    With Me.rptReader
       .DataSource = rssData.Tables(3)
       .DataBind()
    End With
    With in the repeater im not sure how to access the url of the image.

    I can get the title and description like this:
    Code:
      <ul>
        <asp:Repeater ID="rptReader" runat="server">
            <ItemTemplate>
                <li><asp:HyperLink ID="lnkArticle" runat="server"
                     NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "link") %>'
                     Target="_blank"
                     Text='<%# DataBinder.Eval(Container.DataItem, "title")%>' 
                     CssClass="rssLink"/>
                </li>
            </ItemTemplate>
        </asp:Repeater>
        </ul>
    Any idea on how i can get that URL?

  2. #2
    Join Date
    Sep 2004
    Location
    Northeast, FL
    Posts
    332
    You need to flatten out the data before binding it to the grid, the code below should get you started.

    Code:
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim rssFeed As HttpWebRequest = DirectCast(WebRequest.Create("http://sports.yahoo.com/mlb/rss.xml"), HttpWebRequest)
            Dim rssData As DataSet = New DataSet()
            rssData.ReadXml(rssFeed.GetResponse().GetResponseStream())
    
            Dim sb As New System.Text.StringBuilder
            Dim tw As System.IO.TextWriter = New System.IO.StringWriter(sb)
            rssData.WriteXmlSchema(tw)
    
            If rssData.Relations.Count > 0 Then
                For idx As Integer = 0 To rssData.Relations.Count - 1
                    MsgBox(rssData.Relations(idx).RelationName)
                Next
            End If
    
            Dim items As New List(Of item)
            For Each dr As DataRow In rssData.Tables(3).Rows
                Dim item As New item(dr("title"))
    
                Dim rows As DataRow() = dr.GetChildRows("item_content")
                If rows.Length > 0 Then
                    item.Url = rows(0)("url")
                End If
    
                items.Add(item)
            Next
    
            Me.DataGridView1.DataSource = items
            
    
        End Sub
    
        Public Class item
    
            Public Sub New(ByVal title As String)
                Me.Title = title
            End Sub
    
            Public Sub New(ByVal title As String, ByVal url As String)
                Me.Title = title
                Me.Url = url
            End Sub
    
            Private mTitle As String
            Public Property Title() As String
                Get
                    Return mTitle
                End Get
                Set(ByVal value As String)
                    mTitle = value
                End Set
            End Property
    
            Private mUrl As String
            Public Property Url() As String
                Get
                    Return mUrl
                End Get
                Set(ByVal value As String)
                    mUrl = value
                End Set
            End Property
    
        End Class

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles