RSS - Whitespace is not allowed at this location.

Discussion in 'ASP General' started by mark r, May 14, 2008.

  1. mark r

    mark r Guest

    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>
     
    mark r, May 14, 2008
    #1
    1. Advertising

  2. "mark r" <> wrote in message
    news:...
    > 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.

    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, May 15, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oli Filth
    Replies:
    9
    Views:
    3,370
    Uncle Pirate
    Jan 17, 2005
  2. Replies:
    10
    Views:
    804
    Eric Brunel
    Dec 16, 2008
  3. Bouton Jones
    Replies:
    0
    Views:
    1,235
    Bouton Jones
    Jan 6, 2009
  4. Jonathan Groll
    Replies:
    1
    Views:
    329
    Kouhei Sutou
    Jun 27, 2009
  5. Iñaki Baz Castillo
    Replies:
    13
    Views:
    557
    Iñaki Baz Castillo
    May 1, 2011
Loading...

Share This Page