RSS - Whitespace is not allowed at this location.

M

mark r

Trying to create a page like popurls displaying rss feeds from music
sites only im trying with one to start from NME.com and the output
errors with the message "Whitespace is not allowed at this location."

anyone help?

DEMO: http://mngr.co.uk/rss1.asp

Code:
<%@ Language="VBScript" %>
<% Option Explicit %>
<% Response.Charset = "UTF-8" %>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>ASP 101's MegaTokyo RSS Feed Reader</title>
</head>
<body>

<%
If DateDiff("h", Application("MegaTokyoUpdated"), Now()) >= 2 _
Or Request.QueryString("force") <> "" Then

Dim objXML
Dim objItemList
Dim objItem
Dim strHTML
Set objXML = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
objXML.async = False

objXML.setProperty "ServerHTTPRequest", True
objXML.Load("http://nme.com/rss/news.xml")
'objXML.Load(Server.MapPath("megatokyo.xml"))

If objXML.parseError.errorCode <> 0 Then
Response.Write "<pre>" & vbCrLf
Response.Write "<strong>Error:</strong> " &
objXML.parseError.reason
Response.Write "<strong>Line:</strong> " &
objXML.parseError.line & vbCrLf
Response.Write "<strong>Text:</strong> " _
& Server.HTMLEncode(objXML.parseError.srcText) & vbCrLf
Response.Write "</pre>" & vbCrLf
End If

Set objItemList = objXML.getElementsByTagName("item")
Set objXML = Nothing

For Each objItem In objItemList
' MegaTokyo Feed childNodes: 0=title, 1=link, 2=description
strHTML = strHTML & "<p>" & vbCrLf
strHTML = strHTML & "<a href=""" & objItem.childNodes(1).text &
""">"
strHTML = strHTML & "<strong><em>" & objItem.childNodes(0).text
strHTML = strHTML & "</em></strong></a><br />" & vbCrLf
strHTML = strHTML & Replace(objItem.childNodes(2).text, "<br>",
"<br />") & vbCrLf
strHTML = strHTML & "</p>" & vbCrLf
Next

Set objItemList = Nothing

Application.Lock
Application("MegaTokyoContent") = strHTML
Application("MegaTokyoUpdated") = Now()
Application.UnLock
End If
%>

<%= Application("MegaTokyoContent") %>
<!--<%= Application("MegaTokyoUpdated") %>-->

</body>
</html>
 
A

Anthony Jones

mark r said:
Trying to create a page like popurls displaying rss feeds from music
sites only im trying with one to start from NME.com and the output
errors with the message "Whitespace is not allowed at this location."

anyone help?

DEMO: http://mngr.co.uk/rss1.asp

Code:
<%@ Language="VBScript" %>
<% Option Explicit %>
<% Response.Charset = "UTF-8" %>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>ASP 101's MegaTokyo RSS Feed Reader</title>
</head>
<body>

<%
If DateDiff("h", Application("MegaTokyoUpdated"), Now()) >= 2 _
Or Request.QueryString("force") <> "" Then

Dim objXML
Dim objItemList
Dim objItem
Dim strHTML
Set objXML = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
objXML.async = False

objXML.setProperty "ServerHTTPRequest", True
objXML.Load("http://nme.com/rss/news.xml")
'objXML.Load(Server.MapPath("megatokyo.xml"))

If objXML.parseError.errorCode <> 0 Then
Response.Write "<pre>" & vbCrLf
Response.Write "<strong>Error:</strong> " &
objXML.parseError.reason
Response.Write "<strong>Line:</strong> " &
objXML.parseError.line & vbCrLf
Response.Write "<strong>Text:</strong> " _
& Server.HTMLEncode(objXML.parseError.srcText) & vbCrLf
Response.Write "</pre>" & vbCrLf
End If

Set objItemList = objXML.getElementsByTagName("item")
Set objXML = Nothing

For Each objItem In objItemList
' MegaTokyo Feed childNodes: 0=title, 1=link, 2=description
strHTML = strHTML & "<p>" & vbCrLf
strHTML = strHTML & "<a href=""" & objItem.childNodes(1).text &
""">"
strHTML = strHTML & "<strong><em>" & objItem.childNodes(0).text
strHTML = strHTML & "</em></strong></a><br />" & vbCrLf
strHTML = strHTML & Replace(objItem.childNodes(2).text, "<br>",
"<br />") & vbCrLf
strHTML = strHTML & "</p>" & vbCrLf
Next

Set objItemList = Nothing

Application.Lock
Application("MegaTokyoContent") = strHTML
Application("MegaTokyoUpdated") = Now()
Application.UnLock
End If
%>

<%= Application("MegaTokyoContent") %>
<!--<%= Application("MegaTokyoUpdated") %>-->

</body>
</html>

At a guess I would say the its the Cr Lf between these that is the cause:-

<% Response.Charset = "UTF-8" %>
<?xml version="1.0" encoding="UTF-8"?>

Try it like this:-

<%
Option Explicit
Response.Charset = "UTF-8"
Response.CodePage = 65001
%><?xml version="1.0" encoding="UTF-8"?>


Having the xml declaration directly follow the closing %> without a line
break eliminates unwanted whitespace at the top of the XML output.

Note without setting the codepage any non-ASCII characters will be trashed
in the output.
I'm not sure why you are using a FreeThreadedDOMDocument in the way you are
a standard DOMDocument would suffice.

I would create the whole lot as XML in a FreeThreadDOMDocument and store
that DOM in the application object.

Given a FreeThreadedDOMDocument in a variable oDOM sending a reponse would
simply be:-

Response.CharSet = "UTF-8"
oDOM.Save Response

Note strictly speaking the content type should be set to
application/xhtml+xml but since some browsers don't recognise that type as a
HTML type that may not be an option here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top