0

I would like to parse through and display and picture and description for each 'item' in an XML file. I can't figure out the image part, and I've only been able to concatenate the 'description' to display it:

.ASPX:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:Image ID="imgAmberIMG" runat="server" />

        <asp:Label ID="lblDescription" runat="server"></asp:Label>

    </div>
    </form>
</body>
</html>

Code Behind:

Imports System.Xml.Linq
Imports System.Net


Partial Class AmberAlert
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        Dim amberAlert As XDocument = XDocument.Load("http://www.missingkids.com/missingkids/servlet/XmlServlet?act=rss&LanguageCountry=en_US&orgPrefix=NCMC&state=NY")

        For Each xe As XElement In amberAlert.Descendants("item")

            lblDescription.Text += (xe.Element("description").Value) + "<br />"
            imgAmberIMG.ImageUrl = xe.Element("enclosure").Attribute("url").Value

        Next

    End Sub
End Class

I'm at the right elements in the tree; I can display the first picture, and I've been able to access all of the 'description' elements. But I need to have each 'item' element display together.

Thanks!

tahdhaze09
  • 2,220
  • 1
  • 21
  • 36
  • take a look at http://stackoverflow.com/questions/21877/dynamically-rendering-aspimage-from-blob-entry-in-asp-net – volody Mar 30 '12 at 18:30
  • You know, you just answered another question I had about Oracle BLOB last month! But, I need to put my mind to how this will work with parsing an XML file... – tahdhaze09 Mar 30 '12 at 18:36

1 Answers1

0

Use an asp:DataList put your image and description inside of it and use databinding to set their properties. See DataList Class on MSDN which includes an example.

Instead of using a For Each:

Dim missingList = From xe As XElement In amberAlert.Descendants("item")
                  Select New With {
                                      Description = (xe.Element("description").Value) + "<br />",
                                      ImageUrl = xe.Element("enclosure").Attribute("url").Value
                                  }

Then set the DataSource of the DataList to missingList.

JamieSee
  • 12,696
  • 2
  • 31
  • 47