Object required error while parsing XML

Posted on 2006-05-23
Last Modified: 2008-01-09
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("microsoft.XMLDOM")

call objXML.setProperty("ServerHTTPRequest", True)
call objXML.Load(xmlFile)

Set elements = objXML.getElementsByTagName("item")  

For i = 1 to NumberOfLinks
tTitle = elements.item(i).childNodes(0).Text '''''''''''''''''''' The Error Line '''''''''''''''''''''''''''''''

Set objXML = Nothing

The XML Code
<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
    <title>My company RSS Feed</title>
    <description>My company extends products using XML</description>
    <pubDate>Fri, 16 Apr 2006 15:15:00 +0200</pubDate>
      <title>New company started</title>
      <description>Here the description goes</description>
      <pubDate>Fri, 16 Feb 2006 00:00:00 +0200</pubDate>
      <title>New company2 started</title>
      <description>Here2 the description goes</description>
      <pubDate>Fri, 16 Feb 2006 00:00:00 +0200</pubDate>
      <title>New company3 started</title>
      <description>Here3 the description goes</description>
      <pubDate>Fri, 16 Feb 2006 00:00:00 +0200</pubDate>
Question by:quest_capital
    LVL 25

    Expert Comment

    here's something that may help.

    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>{DESCRIPTION}{pubDate}{Author}</td></tr>"
          ErrorMessage = "Error has occured while trying to process " &URLToRSS & "<BR>Please contact web-master"
          Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP.3.0")
                xmlHttp.Open "Get", URLToRSS, false
                RSSXML = xmlHttp.ResponseText
                Set xmlDOM = Server.CreateObject("MSXML2.DomDocument.3.0")
                      xmlDOM.async = false
                Set xmlHttp = Nothing ' clear HTTP object
                Set RSSItems = xmlDOM.getElementsByTagName("item") ' collect all "items" from downloaded RSS
          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
                j = J+1
                if J < MaxNumberOfItems then
                      ItemContent = Replace(ItemTemplate,"{LINK}",RSSlink)
                      if showAll then
                            ItemContent = Replace(ItemContent,"{TITLE}","<div style='padding-left:10px;font-weight:bold;'>"&RSSTitle&"</div>")
                            ItemContent = Replace(ItemContent,"{pubDate}","<div style='font-size:85%;font-weight:bold;font-style:italic;text-align:right;'>Published: "&RSSPubDate&"</div>")
                            ItemContent = Replace(ItemContent,"{Author}","<div style='font-size:85%;font-weight:bold;font-style:italic;text-align:right;'>"&RSSAuthor&"<div align='right' style='padding-right:10px;'><a href='javascript:window.scrollTo(0,0);'><img src='/storage/images/16x_top.gif' alt='Return To The Top Of The Page' border='0' /></a></div></div>")
                            ItemContent = Replace(ItemContent,"{DESCRIPTION}","<div style='font-size:85%;padding:0 10px 0 25px;'>"&RSSDescription&"</div>")
                            ItemContent = Replace(ItemContent,"{TITLE}","<div style='padding-left:10px;'>"&RSSTitle&"</div>")
                            ItemContent = Replace(ItemContent,"{pubDate}","")
                            ItemContent = Replace(ItemContent,"{Author}","")
                            ItemContent = Replace(ItemContent,"{DESCRIPTION}","")
                      end if
                      ItemContent = ""
                End if
          ' writing Footer
          if RSSItemsCount > 0 then
                Response.Write MainTemplateFooter
                Response.Write ErrorMessage
          End If
    End Function

    to use it simply:
    <%Call RSSReader("", 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)
    LVL 52

    Expert Comment

    by:Carl Tawn
    The collection of nodes is zero based, so your code should read:

        For i = 0 to NumberOfLinks - 1
           tTitle = elements.item(i).childNodes(0).Text '''''''''''''''''''' The Error Line '''''''''''''''''''''''''''''''

    Author Comment

    same error
    LVL 25

    Expert Comment

    have you tried my method?

    and I believe they are child.nodeName
    LVL 52

    Accepted Solution

    You may want to check that it is loading the XML ok. I tried it from a file and it worked ok.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now