Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Scott M. Fulton III 19 posts 42 karma points
    Jul 07, 2010 @ 05:42
    Scott M. Fulton III
    0

    XML parsing error in RSS feed XSLT

    Greetings, folks:

    I'm encountering some weird behavior in Umbraco 4.0.4.1, particularly when attempting to visualize any XSLT based on the "RSS Feed" template, including existing code borrowed from CWS:  The browser generates an XML parsing error.  Here's a picture from Firefox 3.6.6:

    The location in question is /umbraco/developer/xslt/xsltVisualize.aspx?rndo=22.8  The code to which it refers is the first html.replace instruction in this segment of the ASP file:

            function encodeDecodeResult(isChecked) {
                var html = jQuery("#result").html();
                if (isChecked) {
                    jQuery("#result").html(
                        html.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g,"<br/>").replace(/\r/g,""));
                } else {
                jQuery("#result").html(
                        html.replace(/<BR>/g, "\n").replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>'));

    Firefox is pointing to the /&/g, which looks perfectly legitimate to me -- the code replaces lone ampersands with the &amp; token.  It's a familiar passage to anyone who's ever tried to "escape" HTML characters, and I don't actually see an error here.

    Trouble is, the problem's not just with Firefox.  Here's the same error cropping up in Google Chrome 5.0.360.4:

    IE8 doesn't show an error; it just visualizes nothing.  Which is perhaps what it's supposed to do.  In any event, I sincerely doubt that the xsltVisualize.aspx file is actually in error here; but once I realize what it may be that I'm doing to cause this problem, I'll learn something valuable about Umbraco.  My thanks to all out there for any clues you can give me.

    Yours,

    /&/gScott Fulton &third;

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Jul 07, 2010 @ 09:57
    Chriztian Steinmeier
    0

    Hi Scott,

    I don't know why it's happening, but the error is a crystal clear XML validation-error - the browser is fed something it thinks is XML, and a lone ampersand is top-priority no-no in XML, so complaining ensues... as to why the page is served as XML - have no clue... can you see the HTTP headers with Firebug or the Developer tools in Chrome/Safari?

    /Chriztian 

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jul 07, 2010 @ 10:16
    Sebastiaan Janssen
    0

    A question you should ask yourself: Do you really need that javascript code to be in your XSLT file? This looks like something that could (and should) be in an external javascript file.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Jul 07, 2010 @ 10:32
    Chriztian Steinmeier
    0

    @Sebastiaan: As I understand it, the error seems to be that the xsltVisualizer.aspx file gets interpreted as XML by the browser(s) - which triggers the error in the JavaScript for the Encode/Decode result checkbox... so I don't think he's having any JavaScript in the XSLT...

    /Chriztian 

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jul 07, 2010 @ 10:55
    Sebastiaan Janssen
    0

    Ah yes, I see now. :) Would be good to see the xslt source to see what might be wrong.

  • Josh Townson 67 posts 162 karma points
    Jul 07, 2010 @ 15:09
    Josh Townson
    0

    If you're using the RSS Feed template, you can't visualize it with the following line left in:

        <xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/>

    just comment it out for the visualization - although you shouldn't be visualizing, as the RSS feed isn't HTML.

    Basically that line changes the content type of the response to be text/xml, which means that unescaped ampersands are invalid, and should cause an error (strict XML). If you get rid of it, everything will be OK for visualizations, but the content type of your feed will be wrong so certain applications consuming it might get upset.

    /Josh

  • Scott M. Fulton III 19 posts 42 karma points
    Jul 07, 2010 @ 16:52
    Scott M. Fulton III
    0

    Bingo.  Yes, Josh, that's the ticket.  Commented that line out, feed visualizes as planned.  Thank you very much!

    Suggestion for Umbraco developers:  The Visualize Feed page is currently set up to automatically visualize whatever it last visualized; and browsers tend to show error pages (like the one in the screenshot) that overwrite the entire window.  Perhaps in the toolbar next to the Visualize XSLT button, someone could add a "Reset Visualizer" button that would perform the same general function as the Delete link in the Visualizer window.  Otherwise, browsers like Firefox will be stuck in a rut.

    Also, perhaps for future editions of the "RSS Feed" template, the ChangeContentType line could be automatically commented out, with a message that says something like, "<!-- Uncomment this instruction when development is complete   -->"

    Thanks again, Josh, you've helped a lot.

    <!-- Scott -->

Please Sign in or register to post replies

Write your reply to:

Draft