ASP RSS Ayrıştırıcısı, Feed Reader
Bu həftə sonu mən laptopuma yapışıb internetə əsaslanan üçün axtarış etdim RSS oxucuları qidalandırın. Səbəb odur ki, mən yazmaq istəyirdim ASP Məzmunun avtomatik olaraq kazınması üçün lenti göstərəcək RSS lenti oxuyucusu HTML e-poçt. Beləliklə, e-poçt bülleteninin bir hissəsini Blog və ya Nəşr məqalələri üçün rezerv etmək istəyən insanlar üçün asanlıqla daxil edilə bilər.
Müştəri skripti yükləyənə və icra edənə qədər JavaScript məzmunu əslində göstərmədiyi üçün JavaScript RSS brauzerlərinin çoxluğu faydalı deyildi. Mənə server tərəfi RSS lenti oxuyucusu lazım idi.
təhlil etmək üçün XML ASP-də qidalandırmaq üçün ASP-də mövcud olan MSXML kitabxanasından istifadə edə bilərsiniz. ASP-dən istifadə edərək XML lentini təhlil etməyin əsas nümunəsi:
<%
' 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
%>
Bu kodda ilk olaraq bir nümunə yaradırıq Msxml2.DOMDocument.6.0
XML ilə işləmək üçün obyekt. Daha sonra XML lentini a-dan yükləyirik URL və yükləmənin uğurlu olub olmadığını yoxlayın. Heç bir səhv yoxdursa, biz XML strukturunda naviqasiya etmək və təyin etdiyiniz elementlərdən məlumatları əldə etmək üçün XPath-dan istifadə edirik. Nəhayət, əldə edilmiş məlumatlarla satış və marketinq əməliyyatlarınızı həyata keçirə bilərsiniz.
Müəyyən sayda sözdən ibarət çıxarış təqdim etmək üçün çıxışı dəyişdirə və mətnin davam etdiyini göstərmək üçün “…” əlavə edə bilərsiniz. Bunu ASP kodunuzda necə edə biləcəyinizə dair bir nümunə:
<%
' 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
%>
Bu kodda biz dəyişdirən bir bölmə əlavə etdik description
müəyyən sayda sözlə (bu nümunədə 30) çıxarış yaratmaq və təsvir daha uzundursa “…” əlavə etmək. tənzimləyə bilərsiniz excerptLength
çıxarışdakı sözlərin sayına nəzarət etmək üçün dəyişən.
Bu modifikasiya sizə satış və marketinq əməliyyatlarınız üçün çıxarış kimi kəsilmiş təsviri təqdim edəcək.
Zəhmət olmasa dəyişdirin http://example.com/feed.xml
Xüsusi XML strukturunuza və tələblərinizə uyğun olaraq element adlarını və məlumatların işlənməsini təhlil etmək və tənzimləmək istədiyiniz XML lentinin URL-i ilə.