quest_capital
asked on
Object required error while parsing XML
I get the error
Object required: 'item(...)'
What is wrong?
Here is the code:
<%
Response.Buffer = True
Dim objXMLHTTP, xml, xmlFile, xmlLocation, xmlDir, elements, i
xmlFile = "http://some_domain/pride/includes/article_index_4.xml"
NumberOfLinks = 3
Dim objXML
Set objXML = Server.CreateObject("micro soft.XMLDO M")
call objXML.setProperty("Server HTTPReques t", True)
call objXML.Load(xmlFile)
Set elements = objXML.getElementsByTagNam e("item")
For i = 1 to NumberOfLinks
tTitle = elements.item(i).childNode s(0).Text '''''''''''''''''''' The Error Line '''''''''''''''''''''''''' '''''
Next
Set objXML = Nothing
%>
The XML Code
<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel>
<title>My company RSS Feed</title>
<link>http://www.mysite.com/</link>
<description>My company extends products using XML</description>
<language>en-uk</language>
<pubDate>Fri, 16 Apr 2006 15:15:00 +0200</pubDate>
<item>
<title>New company started</title>
<link>http://www.mysite.com/news.asp?id=26</link>
<comments>http://www.mysite.com/comments.asp?id=26</comments>
<description>Here the description goes</description>
<pubDate>Fri, 16 Feb 2006 00:00:00 +0200</pubDate>
</item>
<item>
<title>New company2 started</title>
<link>http://www.mysite.com/news.asp?id=26</link>
<comments>http://www.mysite.com/comments.asp?id=26</comments>
<description>Here2 the description goes</description>
<pubDate>Fri, 16 Feb 2006 00:00:00 +0200</pubDate>
</item>
<item>
<title>New company3 started</title>
<link>http://www.mysite.com/news.asp?id=26</link>
<comments>http://www.mysite.com/comments.asp?id=26</comments>
<description>Here3 the description goes</description>
<pubDate>Fri, 16 Feb 2006 00:00:00 +0200</pubDate>
</item>
</channel>
</rss>
Object required: 'item(...)'
What is wrong?
Here is the code:
<%
Response.Buffer = True
Dim objXMLHTTP, xml, xmlFile, xmlLocation, xmlDir, elements, i
xmlFile = "http://some_domain/pride/includes/article_index_4.xml"
NumberOfLinks = 3
Dim objXML
Set objXML = Server.CreateObject("micro
call objXML.setProperty("Server
call objXML.Load(xmlFile)
Set elements = objXML.getElementsByTagNam
For i = 1 to NumberOfLinks
tTitle = elements.item(i).childNode
Next
Set objXML = Nothing
%>
The XML Code
<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel>
<title>My company RSS Feed</title>
<link>http://www.mysite.com/</link>
<description>My company extends products using XML</description>
<language>en-uk</language>
<pubDate>Fri, 16 Apr 2006 15:15:00 +0200</pubDate>
<item>
<title>New company started</title>
<link>http://www.mysite.com/news.asp?id=26</link>
<comments>http://www.mysite.com/comments.asp?id=26</comments>
<description>Here the description goes</description>
<pubDate>Fri, 16 Feb 2006 00:00:00 +0200</pubDate>
</item>
<item>
<title>New company2 started</title>
<link>http://www.mysite.com/news.asp?id=26</link>
<comments>http://www.mysite.com/comments.asp?id=26</comments>
<description>Here2 the description goes</description>
<pubDate>Fri, 16 Feb 2006 00:00:00 +0200</pubDate>
</item>
<item>
<title>New company3 started</title>
<link>http://www.mysite.com/news.asp?id=26</link>
<comments>http://www.mysite.com/comments.asp?id=26</comments>
<description>Here3 the description goes</description>
<pubDate>Fri, 16 Feb 2006 00:00:00 +0200</pubDate>
</item>
</channel>
</rss>
The collection of nodes is zero based, so your code should read:
For i = 0 to NumberOfLinks - 1
tTitle = elements.item(i).childNode s(0).Text '''''''''''''''''''' The Error Line '''''''''''''''''''''''''' '''''
Next
For i = 0 to NumberOfLinks - 1
tTitle = elements.item(i).childNode
Next
ASKER
carl_tawn
same error
same error
have you tried my method?
and I believe they are child.nodeName
and I believe they are child.nodeName
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Function RSSReader(url, numItems, showAll)
URLToRSS = url
MaxNumberOfItems = numItems
MainTemplateHeader = "<table width='100%' cellpadding='0' cellspacing='0'>"
MainTemplateFooter = "</table>"
ItemTemplate = "<tr><td style='border-bottom:1px solid #EEE;'><a href=" & """{LINK}""" & " target='_blank'>{TITLE}</a
ErrorMessage = "Error has occured while trying to process " &URLToRSS & "<BR>Please contact web-master"
Set xmlHttp = Server.CreateObject("MSXML
xmlHttp.Open "Get", URLToRSS, false
xmlHttp.Send()
RSSXML = xmlHttp.ResponseText
Set xmlDOM = Server.CreateObject("MSXML
xmlDOM.async = false
xmlDOM.LoadXml(RSSXML)
Set xmlHttp = Nothing ' clear HTTP object
Set RSSItems = xmlDOM.getElementsByTagNam
Set xmlDOM = Nothing ' clear XML
RSSItemsCount = RSSItems.Length-1
' writing Header
if RSSItemsCount > 0 then
Response.Write MainTemplateHeader
End If
j = -1
For i = 0 To RSSItemsCount
Set RSSItem = RSSItems.Item(i)
for each child in RSSItem.childNodes
Select case lcase(child.nodeName)
case "title"
RSStitle = child.text
case "link"
RSSlink = child.text
case "description"
RSSdescription = child.text
case "pubdate"
RSSPubDate = child.text
case "author"
RSSAuthor = child.text
End Select
next
j = J+1
if J < MaxNumberOfItems then
ItemContent = Replace(ItemTemplate,"{LIN
if showAll then
ItemContent = Replace(ItemContent,"{TITL
ItemContent = Replace(ItemContent,"{pubD
ItemContent = Replace(ItemContent,"{Auth
ItemContent = Replace(ItemContent,"{DESC
else
ItemContent = Replace(ItemContent,"{TITL
ItemContent = Replace(ItemContent,"{pubD
ItemContent = Replace(ItemContent,"{Auth
ItemContent = Replace(ItemContent,"{DESC
end if
write(ItemContent)
ItemContent = ""
End if
Next
' writing Footer
if RSSItemsCount > 0 then
Response.Write MainTemplateFooter
else
Response.Write ErrorMessage
End If
End Function
to use it simply:
<%Call RSSReader("http://hosted.ap.org/lineups/WORLDHEADS-rss_2.0.xml?SITE=RANDOM&SECTION=HOME", 5, False)%>
5 is the number of articles I want to display
False will display the titles only (change it to true for the whole article)