Copied to clipboard

Flag this post as spam?

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


  • Kasper Dyrvig 246 posts 379 karma points
    Oct 26, 2011 @ 09:03
    Kasper Dyrvig
    0

    RSS feed URL cause error

    Hi

    I'm working with a feed from Trustpilot, I want to create a custom view of the costumers reviews. I'm creating the xslt out of this post.

    But when I insert the URL for the feed I get this error:

    System.Xml.XmlException: '', hexadecimal value 0x1F, is an invalid character. Line 1, position 91. 

    I have discovered that if I remove the first dot in the URL I don't get an error, but then the link isn't correct so that really dosen't help me.

    I'm using Umbraco v 4.5.2.

    Any help will be appreciated!

  • Chriztian Steinmeier 2720 posts 8225 karma points MVP 4x admin c-trib
    Oct 26, 2011 @ 09:23
    Chriztian Steinmeier
    0

    Hi Kasper,

    Looks like an error in the feed (or maybe a pasted character in the stylesheet?)

    Try these:

    1. Can you open the feed URL in a browser?

    2. Can you open the XSLT file in Internet Explorer?

    /Chriztian 

     

     

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 26, 2011 @ 09:36
    Kasper Dyrvig
    0

    Hi Chriztian

    1: Yes.

    2: If you by that mean paste the direct url for the xslt file in IE, then yes.

  • Chriztian Steinmeier 2720 posts 8225 karma points MVP 4x admin c-trib
    Oct 26, 2011 @ 09:39
    Chriztian Steinmeier
    0

    OK - great; If you can open both the feed XML and the XSLT as plain XML files, it's not a cut 'n paste error.

    Then it's bound to be something that happens during the processing - are you doing any Replace stuff, Date conversion etc.?

    Maybe paste some of the code?

    /Chriztian

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 26, 2011 @ 09:39
    Kasper Dyrvig
    0

    Note: I have now inserted a namespace that Trustpilot uses in the rss feed. But it makes no difference to this issue.

    xmlns:tp="http://www.trustpilot.dk/rss/"
  • Kasper Dyrvig 246 posts 379 karma points
    Oct 26, 2011 @ 09:41
    Kasper Dyrvig
    0
    <xsl:param name="currentPage"/>
    <xsl:variable name="numberOfItems" select="10" />
    <xsl:variable name="excerptLength" select="200" />
    <xsl:variable name="feed" select="string('http://trustbox.trustpilot.com/r/example.com.xml')"/>

    <xsl:template match="/">
      <xsl:choose>
        <xsl:when test="$feed != ''">
          <xsl:variable name="feedContent" select="umbraco.library:GetXmlDocumentByUrl($feed, 3600)"/>
          <xsl:choose>
            <xsl:when test="$feedContent != 'error'">
              <xsl:call-template name="renderFeed">
                <xsl:with-param name="feedContent" select="$feedContent"/>
              </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
              <p><strong>Feed Viewer Macro Error: Error fetching feed</strong><br />The feed '<xsl:value-of select="$feed"/>' could not be loaded. Verify that the feed url exists and that you have anactive internet connection</p>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
          <p><strong>Feed Viewer Macro Error: No feed chosen</strong><br />Please make sure to add a value in the "Feed Url" parameter
          </p>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

    <xsl:template name="renderFeed">
      <xsl:param name="feedContent"/>
      <xsl:if test="count($feedContent//item) &gt; 0">
        <ul class="feedList">
          <xsl:for-each select="$feedContent//item">
            <xsl:if test="position() &lt;= $numberOfItems">
              <li>
                <small><xsl:value-of select="umbraco.library:LongDate(pubDate)"/></small>
                <h4><href="{link}"><xsl:value-of select="title" disable-output-escaping="yes"/></a>
                </h4>
                <xsl:choose>
                  <xsl:when test="string($excerptLength) != '0'">
                    <p>
                      <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(description), number($excerptLength), '...')" disable-output-escaping="yes"/>
                    </p>
                  </xsl:when>
                  <xsl:otherwise>
                    <!-- <xsl:value-of select="description" disable-output-escaping="yes"/> -->
                  </xsl:otherwise>
                </xsl:choose>
              </li>
            </xsl:if>
          </xsl:for-each>
          <li class="last"><xsl:text disable-output-escaping="yes">&amp;</xsl:text>nbsp;</li>
        </ul>
      </xsl:if>
    </xsl:template>
  • Chriztian Steinmeier 2720 posts 8225 karma points MVP 4x admin c-trib
    Oct 26, 2011 @ 09:44
    Chriztian Steinmeier
    0

    - Can you see from the trace, which method ends up throwing the exception?

    /Chriztian

     

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 26, 2011 @ 09:45
    Kasper Dyrvig
    0

     

    Error occured
    System.Xml.XmlException: '', hexadecimal value 0x1F, is an invalid character. Line 1, position 91. 
    at System.Xml.XmlTextReaderImpl.Throw(Exception e) 
    at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args) 
    at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars) 
    at System.Xml.XmlTextReaderImpl.ParseText() 
    at System.Xml.XmlTextReaderImpl.ParseElementContent() 
    at System.Xml.XmlTextReaderImpl.Read() 
    at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace) 
    at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) 
    at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) 
    at System.Xml.XmlDocument.Load(XmlReader reader) 
    at System.Xml.XmlDocument.LoadXml(String xml) 
    at umbraco.library.GetXmlDocumentByUrl(String Url) 
    at umbraco.library.GetXmlDocumentByUrl(String Url, Int32 CacheInSeconds)

     

  • Chriztian Steinmeier 2720 posts 8225 karma points MVP 4x admin c-trib
    Oct 26, 2011 @ 09:53
    Chriztian Steinmeier
    0

    It's definitely the XML from the feed that's causing this (or Umbraco's way of loading it, at least...)

    Try swapping the GetXmlDocumentByUrl() function with the native document() function and see if that is able to load the file:

    <xsl:variable name="feedContent" select="document($feed)" />

    /Chriztian

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 26, 2011 @ 09:55
    Kasper Dyrvig
    0

    :( No, it's the same

  • Chriztian Steinmeier 2720 posts 8225 karma points MVP 4x admin c-trib
    Oct 26, 2011 @ 10:10
    Chriztian Steinmeier
    0

    Hi Kasper,

    I don't know how to fix this for you, but I think I know what's happening - the server is Gzip'ing the response (even though it's not requested to) - browsers handle this transparently to us, but apparently the underlying .NET frameworks don't :-(

    /Chriztian

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 26, 2011 @ 10:25
    Kasper Dyrvig
    0

    Okay. Well, thanks for the explanation and the help so far. I'll post again if a solution turns up.

  • Chriztian Steinmeier 2720 posts 8225 karma points MVP 4x admin c-trib
    Oct 26, 2011 @ 10:49
    Chriztian Steinmeier
    1

    OK, with a little help from @leekelleher, here's a link to some information which might help:

    http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream(v=vs.90).aspx#11

    Though, as I see it, you'll probably need to create an extension to handle it...

    /Chriztian

  • Lee Kelleher 3925 posts 15033 karma points MVP 10x admin c-trib
    Oct 26, 2011 @ 11:38
    Lee Kelleher
    1

    I've added a new method to uComponents that should be able to handle this.  I haven't tested it extensively, but should work (fingers crossed).

    You'll need to download and compile the latest source, (or wait until the next release of uComponents - which might be another week away yet)

    http://ucomponents.codeplex.com/SourceControl/changeset/changes/84974

     

    In the XML extension, the method is called "GetXmlDocumentByUrl", with an extra parameter for specifying whether to check for GZipped data.

    <xsl:copy-of select="ucomponents.xml:GetXmlDocumentByUrl('http://path/to/rss', 600, true())" />

    Good luck!

    Cheers, Lee.

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 26, 2011 @ 14:09
    Kasper Dyrvig
    0

    Waow. Thanks a lot guys! Unfortunately we are now moving in to an area where I might need to contact the IT department :-/

    Thanks again. I'll let you know how it turns out.

    If any other people has ideas you're welcome to post them :-)

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 27, 2011 @ 14:47
    Kasper Dyrvig
    0

    Okay here is an unecspected turn...

    Trustpilot has just made a new way to get data from them: JSON

    Not that I'm an expert in JSON, but thougt it was a good alternative. Can XSLT an JSON work together?

  • Dan Okkels Brendstrup 101 posts 197 karma points
    Oct 28, 2011 @ 10:46
    Dan Okkels Brendstrup
    1

    XSLT isn't built for string parsing, and has no native ability to parse JSON. You'd need some way to convert the JSON to XML first.

    If that proves to be necessary, and if you're comfortable depending on a third-party service, I've found YQL to be perfect for that:

    http://developer.yahoo.com/yql/console/#h=select%20*%20from%20json%20where%20url%3D%22http%3A//pipes.yahoo.com/pipes/pipes.popular%3F_out%3Djson%22%20and%20itemPath%20%3D%20%22value.items%22

    You'll probably want to cache the output with Darren Ferguson's FeedCache package, I'd imaginge.

  • Kasper Dyrvig 246 posts 379 karma points
    Nov 01, 2011 @ 10:36
    Kasper Dyrvig
    0

    Thanks for the tip Dan

Please Sign in or register to post replies

Write your reply to:

Draft