Friday, November 20, 2015

Evanced Code for Dynamically Pulling Events in ASPX

I can't take the credit for this one - this was all our IT department bailing me out. I needed to dynamically grab the events through with the XML or JSON feed so I could display them on our OPAC. I can do the front-end piece and if this was PHP no problem, but it was much faster to toss pride away and just ask for help.

This code assumes you only have on URL (mURL) - if you have mutliple locations you'll need to create a dynamic solution. This was a pretty rapid test, but we will be adding in dynamic code. Once we do, I'll update the page accordingly.

SINGLE EVANCED FEED
<script runat="server">
        Sub Page_Load()
            If Not Page.IsPostBack Then
               
                Dim mURL As String

                mURL = "http://toledolibrary.evanced.info/signup/eventsxml.aspx?dm=exml&nd=365&lib=1010&ongoing=1"

                Dim xmlDoc As New XmlDocument()
                xmlDoc.Load(mURL)
                Dim nodes As XmlNodeList = xmlDoc.DocumentElement.SelectNodes("/event/item")
                Dim pTitle As String = ""
                Dim pTitleCk As String = ""
                Dim pDate As String = ""
                Dim pTime As String = ""
                Dim pEndDate As String = ""
                Dim pDescription As String = ""
                Dim pLocation As String = ""
                Dim pLibrary As String = ""
                Dim pLink As String = ""
                Dim intCount As Integer = 0
                Dim pTest as String

                For Each node As XmlNode In nodes

                    pTitle = node.SelectSingleNode("title").InnerText
                    pDate = node.SelectSingleNode("date").InnerText
                    pTime = node.SelectSingleNode("time").InnerText
                    pEndDate = node.SelectSingleNode("enddate").InnerText
                    pDescription = node.SelectSingleNode("description").InnerText
                    pLocation = node.SelectSingleNode("location").InnerText
                    pLibrary = node.SelectSingleNode("library").InnerText
                    pLink = node.SelectSingleNode("link").InnerText

                    If (pTitle = pTitleCk) Then
                    Else

                        'Eliminate HTML tags
                        pDescription = pDescription.Replace("<p>", "")
                        pDescription = pDescription.Replace("</p>", "")
                        pDescription = pDescription.Replace("<br>", "")

                        pTest = pTest & "<div class='event pull-left'><a class='swipebox-video' href='" & pLink & "?swipeboxVideo=1'><h2 class=''>" & pTitle & "</h2></a><div class=''>" & pDate & " (" & pTime & ")<br>" & pDescription & "</div></div>"
                       
                        'pTest = pTest & "<div class='event pull-left'><a href='" & pLink & "'><h2 class=''>" & pTitle & "</h2></a><div class=''>" & pDate & " (" & pTime & ")<br>" & pDescription & "<a class='more-info' href='" & pLink & "'> More Info</a></div></div>"
                       
                        'Response.Write(pDescription & "<br>" & pLibrary & ":  " & pLocation & "<br><br>")
                        '<a href='" & pLink & "'>More Info</a><br><br>")

                            intCount = intCount + 1
                           
                          Literal1.Text = pTest 

                    End If

                    pTitleCk = pTitle

                Next
               
               
            End If
        End Sub
    </script>

This is an example of the page in action:
http://images2.toledolibrary.org/imagewall/_new/2015%20-%20OPAC/index.aspx

No comments:

Post a Comment