Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > RSS - Whitespace is not allowed at this location.

Reply
Thread Tools

RSS - Whitespace is not allowed at this location.

 
 
mark r
Guest
Posts: n/a
 
      05-14-2008
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.FreeThreadedDOMDocumen t")
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>
 
Reply With Quote
 
 
 
 
Anthony Jones
Guest
Posts: n/a
 
      05-15-2008

"mark r" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.FreeThreadedDOMDocumen t")
> 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.

--
Anthony Jones - MVP ASP/ASP.NET


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Splitting text at whitespace but keeping the whitespace in thereturned list MRAB Python 3 01-26-2010 11:36 PM
Two ways to generate RSS - rss/maker and rss/2.0 - which is better? Jonathan Groll Ruby 1 06-27-2009 03:53 AM
Novice Developer Errors: "Non-whitespace characters are not allowed"and IE BG image Bouton Jones XML 0 01-06-2009 07:20 PM
Structure using whitespace vs logical whitespace cmdrrickhunter@yaho.com Python 10 12-16-2008 03:51 PM
Whitespace where I don't want whitespace! Oli Filth HTML 9 01-17-2005 08:47 PM



Advertisments