PDA

View Full Version : ASP/XML/RSS inserting an <item>?


Stanlee
09-20-2005, 06:38 PM
I'm building an RSS feed for an ASP/SQLdb web application and I'm NEARLY there BUT I'm actually quite new to XML... ANYhoo here's the problem in a nutshell:

As it stands this code inserts a new <item> no problem...
but it's putting it OUTSIDE of the <channel> tag (therefore making it an invalid RSS 2 document)


Here's me ASP!....

Set ObjXML = Server.CreateObject("Microsoft.XMLDOM")

'Load the XML file...
blnFileExist = objXML.load(server.mappath("RSS_FEED.xml"))

'If the file already exists, continue and make a new record . If it's not, create a new one!
If blnFileExist = False Then
ObjXML.appendChild(objXML.createProcessingInstruction("xml", "version=""1.0"""))
ObjXML.appendChild(objXML.createProcessingInstruction("rss", "version=""2.0""")) ' need to remove the question mark that gets generated here!
ObjXML.appendChild(objXML.createElement("CHANNEL"))
IntID = PAGEID '(This PAGEID value is a numeric coming from an SQL DB)
Else

'*
IntID = PAGEID
End If

'Create the elements to insert data into...
Set objXMLe = objXML.createElement("item")
ObjXMLe.appendChild(objXML.createElement("id"))
ObjXMLe.appendChild(objXML.createElement("title"))
ObjXMLe.appendChild(objXML.createElement("link"))
ObjXMLe.appendChild(objXML.createElement("description"))
ObjXMLe.appendChild(objXML.createElement("pubDate"))

'Insert the data into the XML elements...
ObjXMLe.childNodes(0).text = intID ' Need this to allow multiple pages!
ObjXMLe.childNodes(1).text = PAGETITLE
ObjXMLe.childNodes(2).text = LINK
ObjXMLe.childNodes(3).text = DESCRIPTION
ObjXMLe.childNodes(4).text = strRFC882DATETIME

'Save the RSS file...
ObjXML.documentElement.appendChild(objXMLe.cloneNode(True))
ObjXML.save(server.mappath("RSS_FEED.xml"))

'Clear the connection to save system resources
Set objXMLe = Nothing
Set objXML = Nothing

*
Righto then, I think THIS is where my problem is... as it stands this code inserts a new <item>
but it's putting it OUTSIDE of the <channel> tag therefore making it an invalid RSS 2 document

(The value of PAGEID is an numeric value passed in a querystring (it's a document ID))



I've never posted to one of these things so I don't know if it's the done thing to post a big lump-a-code like that, but hey!

and finally HELLO ALL! :thumbsup:

Dave