Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > RSS and Atom
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
RSS and Atom Ask questions, get answers, discuss creating RSS and Atom feeds or programming apps or sites that create or consume RSS/Atom. Please leave any RSS/Atom politics out of this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the RSS and Atom section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 19th, 2007, 11:51 AM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default removeChild help

I have an rss feed from an external server. Reading it with classic asp works fine, but I want to delete certain <item>'s from it. I have been trying for days but can't get it to work.

When I get all the <item>'s with xmlDOM.getElementsByTagName("item"), I want to delete all double titles (<title>), because I need to create a list of unique authors (which are in the title). I use a For each to walk through the original collection of items and use a comma seperated string to hold unique titles. When a <title> alreade is in the string, that <item> must be deleted.

I've been trying and trying, but can't find the solution,.. it sounds like it must be real simple.

I tried this: http://www.devguru.com/Technologies/...moveChild.html
and different combinations,.. it ends up in errors like this Object doesn't support this property or method: 'removeChild'

I use MSXML2.Domdocument.3.0, I tried version 5 and 6, tried Microsoft.XmlDom like in the examples.)

Someone can point me in the right direction?
Reply With Quote
  #2 (permalink)  
Old November 19th, 2007, 11:56 AM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My code (ASP):

Public Sub ReadRSSDistinct(strURL)

    Dim URLToRSS, MaxNumberOfItems, ErrorMessage, RSSItemsCount
    Dim xmlHttp, xmlDOM, RSSXML
    'Dim RSSItems public
    Dim RSSItem
    Dim blnDelete
    Dim i
    Dim child
    Dim strAuthors
    Dim RSSAuthor

    Dim objRoot
    Dim objExNode
    Dim oldChild

    Response.Expires = -1

    ' URL to RSS Feed to display
    URLToRSS = strURL

    '
    ErrorMessage = ""

    ' ================================================

    Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
    xmlHttp.Open "Get", URLToRSS, False
    xmlHttp.Send()
    RSSXML = xmlHttp.ResponseText

    Set xmlDOM = Server.CreateObject("MSXML2.DomDocument.3.0")
    xmlDOM.async = False
    xmlDOM.validateOnParse = False
    xmlDOM.resolveExternals = False

    If Not xmlDOM.LoadXml(RSSXML) Then
        ErrorMessage = "Can not load XML:" & vbCRLF & xmlDOM.parseError.reason & vbCRLF & ErrorMessage
    End If

    Set xmlHttp = Nothing ' clear HTTP object
    Set RSSItems = xmlDOM.getElementsByTagName("item") ' collect all "items" from downloaded RSS

    RSSItemsCount = RSSItems.Length - 1

    ' if not <item>..</item> entries, then try to get <entry>..</entry>
    If RSSItemsCount = -1 Then
        Set RSSItems = xmlDOM.getElementsByTagName("entry") ' collect all "entry" (atom format) from downloaded RSS
        RSSItemsCount = RSSItems.Length - 1
    End If

    If Not RSSItemsCount = -1 Then

        For i = 0 To RSSItemsCount

            Set RSSItem = RSSItems.Item(i)
            blnDelete = False

            For Each child in RSSItem.childNodes

                Select case lcase(child.nodeName)
                    Case "title"
                        RSSAuthor = GetAuthor(child.text)
                        If Len(strAuthors) = 0 Then
                            strAuthors = Trim(RSSAuthor)
                            blnDelete = True
                        Else
                            If InStr(strAuthors, Trim(RSSAuthor)) = 0 Then
                                strAuthors = strAuthors & "," & Trim(RSSAuthor)
                                blnDelete = False
                            Else
                                'Response.Write "Delete: " & RSSAuthor & "<br />"
                                blnDelete = True
                            End If
                        End If

                        If blnDelete = True Then

                            If RSSItem Is Nothing Then
                                 Response.Write "Nothing: " & RSSAuthor & "<br />"
                            Else
                                Dim childitem
                                Dim objRootItem

                                Set objRoot = xmlDOM.getElementsByTagName("item")

                                Set objExNode = objRoot.Item(i)
                                objRoot.removeChild(objExNode)


                            End if
                        End If
                End Select
            Next
        Next
    End If


    If Len(ErrorMessage) > 0 Then
        Response.Write "<script language='javascript'>alert('" & ErrorMessage & "');</script>"
    End If

    Set xmlDOM = Nothing ' clear XML

End Sub
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
document.DocumentElement.RemoveChild Error jrbancroft C# 2005 2 August 7th, 2006 10:36 PM
Need help with documentElement.removeChild adsioii XSLT 2 January 16th, 2004 01:12 PM



All times are GMT -4. The time now is 06:22 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.