我在ASP Classic中解析并显示RSS源,我想按字母顺序按特定节点对项目进行排序。
Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True
xmlDOM.Load("http://myfeedhere.xml")
Set itemList = xmlDOM.getElementsByTagName("item")
''# Then I am getting the values of each node this way:
For Each item in itemList
For Each child in item.childNodes
Select case lcase(child.nodeName)
case "title"
title = child.text
case "link"
link = child.text
case "fname"
fname = child.text
case "lname"
lname = child.text
case "media:content"
media = child.getAttribute("url")
End Select
next
我需要通过lname“节点对itemList进行排序,这样做的最佳方法是什么..
当我只需要两个节点时,添加标题和链接到字典对象。我在按键数组上调用了quicksort然后相应地输出。此外,我必须为重复的姓氏做好准备,这意味着姓氏不能成为关键。
答案 0 :(得分:0)
得到帮助并非常感谢http://www.4guysfromrolla.com/webtech/012799-3.shtml 用于二维快速排序功能 我制定了一个解决方案(除了告诉客户更新到.net和C#)
...
dim xmlDOM,itemList,currentLetter
Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True
xmlDOM.Load("http://yourrssfeedhere.xml")
Set itemList = xmlDOM.getElementsByTagName("item")
dim itemListLength
itemListLength = itemList.length
dim lastIndex
lastIndex = itemListLength -1
'get the value of the last index of all the items
dim byLastName()
redim byLastName(lastIndex,3)
' set two-dimensinal array indexes, ([lastIndexofItemlist],[#of fields])
dim it
For Each item in itemList
itemCount = itemCount + 1
For Each child in item.childNodes
Select case lcase(child.nodeName)
' loop through each node of item and set variable, set each case for your specific nodes in each <item>
' (i.e <category>,<lname>,etc)
case "title"
title = child.text
case "description"
description = child.text
case "link"
link = child.text
case "pubdate"
pubdate = child.text
case "fname"
fname = child.text
case "lname"
lname = child.text
case "media:content"
media = child.getAttribute("url")
End Select
next
i = itemCount-1
byLastName(i,0) = title
byLastName(i,1) = link
byLastName(i,2) = lname
byLastName(i,3) = fname
next
dim namesLength
namesLength = Ubound(byLastName)
'last index of bylastname
for n = 0 to namesLength
' simple output before sort
Response.Write("<p> Last Name :" & byLastName(n,2) & ", First Name :" & byLastName(n,3) &"</p>")
next
Response.Write("<p> Sorted:</p>")
Call QuickSort(byLastName,0,ubound(byLastName,1),2)
'the last parameter is the field to sort the array on ,
' in this case 2 = lname
for n = 0 to namesLength
' output to test sort
Response.Write("<p> Last Name :" & byLastName(n,2) & ", First Name :" & byLastName(n,3) &"</p>")
next