ASP-RSS-analizilo, Fluolegilo
Ĉi-semajnfine, mi estis gluita al mia tekkomputilo, serĉante la reton por rete RSS nutri legantojn. La kialo estas, ke mi volis skribi an ASP RSS-flua leganto, kiu montrus la fonton, por ke la enhavo aŭtomate skrapiĝu en HTML retpoŝto. Do, por homoj, kiuj volas rezervi parton de sia retpoŝta bulteno por siaj Blogaj aŭ Publikaj artikoloj, ĝi povus esti facile korpigita.
Ĉar JavaScript fakte ne montras la enhavon ĝis la kliento ŝargas kaj efektivigas la skripton, la amaso da JavaScript RSS-retumiloj ne estis utila. Mi bezonis servil-flankan RSS-fluan legilon.
Analizi an XML feed en ASP, vi povas uzi la MSXML-bibliotekon kiu estas disponebla en ASP. Jen baza ekzemplo pri kiel analizi XML-fluon uzante ASP:
<%
' Create an instance of the MSXML DOMDocument object
Set xmlDoc = Server.CreateObject("Msxml2.DOMDocument.6.0")
' Load the XML feed from a URL
xmlDoc.async = False
xmlDoc.load("http://example.com/feed.xml")
' Check if the XML is loaded successfully
If xmlDoc.parseError.errorCode <> 0 Then
Response.Write "Error loading XML: " & xmlDoc.parseError.reason
Else
' Navigate through the XML structure and retrieve data
Set items = xmlDoc.selectNodes("//item") ' Change "item" to the appropriate XML element name in your feed
' Loop through the items
For Each item In items
' Access elements within each item
title = item.selectSingleNode("title").text
link = item.selectSingleNode("link").text
description = item.selectSingleNode("description").text
' Perform your sales and marketing operations with the retrieved data
' For example, you can insert this data into a database or display it on a webpage.
Next
End If
' Clean up the XML document
Set xmlDoc = Nothing
%>
En ĉi tiu kodo, ni unue kreas ekzemplon de la Msxml2.DOMDocument.6.0
objekto labori kun XML. Ni tiam ŝargas la XML-fluon de a URL kaj kontrolu ĉu la ŝarĝo sukcesis. Se ne estas eraroj, ni uzas XPath por navigi tra la XML-strukturo kaj retrovi datumojn de la elementoj, kiujn vi specifas. Fine, vi povas plenumi viajn vendajn kaj merkatajn operaciojn kun la eltrovitaj datumoj.
Vi povas modifi la eligon por provizi eltiraĵon kun specifa nombro da vortoj kaj poste aldoni "..." por indiki ke la teksto daŭras. Jen ekzemplo de kiel vi povas fari tion en via ASP-kodo:
<%
' Create an instance of the MSXML DOMDocument object
Set xmlDoc = Server.CreateObject("Msxml2.DOMDocument.6.0")
' Load the XML feed from a URL
xmlDoc.async = False
xmlDoc.load("http://example.com/feed.xml")
' Check if the XML is loaded successfully
If xmlDoc.parseError.errorCode <> 0 Then
Response.Write "Error loading XML: " & xmlDoc.parseError.reason
Else
' Navigate through the XML structure and retrieve data
Set items = xmlDoc.selectNodes("//item") ' Change "item" to the appropriate XML element name in your feed
' Loop through the items
For Each item In items
' Access elements within each item
title = item.selectSingleNode("title").text
link = item.selectSingleNode("link").text
description = item.selectSingleNode("description").text
' Modify the description to include an excerpt with a specific number of words
excerptLength = 30 ' Change this number to your desired word count
descriptionArray = Split(description, " ")
If UBound(descriptionArray) > excerptLength Then
excerpt = Join(LBound(descriptionArray, excerptLength), " ") & "..."
Else
excerpt = description
End If
' Perform your sales and marketing operations with the excerpt
' For example, you can insert this data into a database or display it on a webpage.
Next
End If
' Clean up the XML document
Set xmlDoc = Nothing
%>
En ĉi tiu kodo, ni aldonis sekcion kiu modifas la description
krei eltiraĵon kun specifa nombro da vortoj (30 en ĉi tiu ekzemplo) kaj aldonas "..." se la priskribo estas pli longa. Vi povas ĝustigi la excerptLength
variablo por kontroli la nombron da vortoj en la eltiraĵo.
Ĉi tiu modifo provizos al vi detranĉitan priskribon kiel eltiraĵon por viaj vendaj kaj merkataj operacioj.
Bonvolu anstataŭigi http://example.com/feed.xml
kun la URL de la XML-fluo vi volas analizi kaj ĝustigi la elementonomojn kaj datuman uzadon laŭ via specifa XML-strukturo kaj postuloj.