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
    Apr 06, 2011 @ 14:12
    Kasper Dyrvig
    0

    XSLT for external xml-feed - error when saving

    Hi all,

    I got gray hairs because of this... I have created a xslt (the old xslt schema) for viewing data from a xml. The funny thing is that it works perfectly if I save the xml file on a server, but it dosen't when I set it to get the xml from the actual "source domain".

    The error message I get:

    System.Xml.XmlException: An error occurred while parsing EntityName. Line 4, position 106.
    at System.Xml.XmlTextReaderImpl.Throw(Exception e)
    at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
    at System.Xml.XmlTextReaderImpl.Throw(String res)
    at System.Xml.XmlTextReaderImpl.ParseEntityName()
    at System.Xml.XmlTextReaderImpl.ParseEntityReference()
    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)

    The critical XSLT:

    <xsl:variable name="feed" select="umbraco.library:GetXmlDocumentByUrl('http://xml.mysourcedomain.dk/info.aspx?ProductId=87181', number(1800))"/>

    If I save the XML and put it on a server, like this:

    <xsl:variable name="feed" select="umbraco.library:GetXmlDocumentByUrl('http://xml.mydomain.dk/87181.xml', number(1800))"/>

    ... it works perfect.

     

    I hope some of you have a solution!! Thanks.

  • Kasper Dyrvig 246 posts 379 karma points
    Apr 06, 2011 @ 14:18
    Kasper Dyrvig
    0

    Note: The "critical xslt" acturlly contains "http://" in the url, but the forum mix it up...

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 06, 2011 @ 19:30
    Jan Skovgaard
    0

    Hi Kasper

    What version of Umbraco is this happening on?

    /Jan

  • Kasper Dyrvig 246 posts 379 karma points
    Apr 07, 2011 @ 09:21
    Kasper Dyrvig
    0

    umbraco v 4.0.3

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 07, 2011 @ 15:42
    Jan Skovgaard
    0

    Hi Kasper

    What happens if you mit the cache parameter and only call the url?

    Same error?

    And are you sure that it's not another line in the XSLT the is the cause? Could you provide a bit more of the code?

    /Jan

  • Kasper Dyrvig 246 posts 379 karma points
    Apr 07, 2011 @ 15:49
    Kasper Dyrvig
    0

    It's the same... I have research me to the conclusion that it is the feed and not the XSLT (as it is now) that causes the error...

    <xsl:param name="currentPage"/>
    <xsl:variable name="day" select="Exslt.ExsltDatesAndTimes:dayinweek()"/>
    <xsl:variable name="dayStrike" select="7"/>
    <xsl:variable name="feed">
        <xsl:choose>
          <xsl:when test="$day = $dayStrike">
            <xsl:value-of select="$currentPage/data [@alias = 'bodyHeaderSub']"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$currentPage/data [@alias = 'bodyHeader']"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
    <xsl:variable name="cacheRate" select="number(1800)"/>
    <xsl:template match="/">
      <xsl:choose>
        <xsl:when test="$feed != ''">
          <xsl:variable name="feedContent" select="umbraco.library:GetXmlDocumentByUrl($feed, number($cacheRate))"/>
          <xsl:choose>
            <xsl:when test="$feedContent != 'Fejl i feed-indhold'">
              <xsl:call-template name="renderFeed">
                <xsl:with-param name="feedContent" select="$feedContent"/>
              </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
              <p>
                <strong>Error</strong></p>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
          <p>
            <strong>Error again</strong>
          </p>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

     

    A have cutted down the xml to only contain

    <productinfo><productid>87181</productid></productinfo>
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 07, 2011 @ 15:55
    Jan Skovgaard
    0

    Hi Kasper

    Am I blind or is it correct that I can't see the "renderFeed" template?

    So you have created the feed yourself? Could this perhaps have something to do with the encoding of the XML document? Is it saved as UTF-8? (Long shot).

    /jan

  • Kasper Dyrvig 246 posts 379 karma points
    Apr 07, 2011 @ 15:58
    Kasper Dyrvig
    0

    Forgot to tell... the code above is the is what calls the xml. I use this code on other websites to get weather data, but here it just won't work. I have tried with other urls in the code - and it works just great. But not with the feed I actually needs!

    This one is giving a major headache...

    UPDATE: The feed is created dynamicly on another website. It is thair productinformation I try to render on the website I'm currently working on. I have tried to make the feed both with and without the encoding... same result

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 07, 2011 @ 16:00
    Jan Skovgaard
    0

    Yes, it's indeed an odd one. Probably one of those where it's just a little stupid thing that's the cause of all evil...

    What does the renderFeed template look like?

    /Jan

  • Kasper Dyrvig 246 posts 379 karma points
    Apr 07, 2011 @ 16:07
    Kasper Dyrvig
    0

    You asked for it...

    <xsl:template name="renderFeed">
      <xsl:param name="feedContent"/>
      <xsl:if test="count($feedContent//ProductInfo) &gt; 0">
        <div class="prod_img">
          <div id="img_opacity">
            <h1>
              <xsl:value-of select="$feedContent//AboutHotel/HeadLine"/>
            </h1>
          </div>
          <xsl:choose>
            <xsl:when test="$day = $dayStrike">
              <div id="spar_bg">
                <p>
                  <span id="spar_text">
                    <xsl:value-of select="umbraco.library:GetDictionaryItem('Your discount')"/>
                  </span>
                </p>
                <br />
                <span id="spar_price">
                  <xsl:value-of select="$feedContent//SavePrice"/>
                  <xsl:value-of select="umbraco.library:GetDictionaryItem('CommaStroke')"/>
                </span>
              </div>
              <div id="pris_bg">
                <span id="pris_text">
                  <xsl:value-of select="umbraco.library:GetDictionaryItem('Your price only')"/>
                </span>
                <br />
                <span id="pris_price">
                  <xsl:value-of select="$feedContent//Price"/>
                  <xsl:value-of select="umbraco.library:GetDictionaryItem('CommaStroke')"/>
                </span>
              </div>
            </xsl:when>
            <xsl:otherwise>
              <div id="off_img">
                <div id="off_isOff">
                  <xsl:value-of select="umbraco.library:GetDictionaryItem('The Strike is gone')"/>
                </div>
              </div>
            </xsl:otherwise>
          </xsl:choose>
        </div>
        <div class="content_wrapper">
          <xsl:choose>
            <xsl:when test="$day = $dayStrike">
              <div id="content_text">
                <h2>
                  <xsl:value-of select="$feedContent//AboutHotel/SubHeadLine"/>
                </h2>
                <p>
                  <xsl:value-of select="$feedContent//AboutHotel/HotelDescription"/>
                </p>
                <div class="menu">
                  <ul>
                    <li>
                      <div class="travel_info_tab_wrap">
                        <div class="travel_info_tab_left"></div>
                        <div class="travel_info_tab_center">
                          <a href="#" onmouseover="easytabs('1', '1');" onfocus="easytabs('1', '1');" onclick="return false;"
                            title="" id="tablink1"><xsl:value-of select="umbraco.library:GetDictionaryItem('About the hotel')"/></a>
                        </div>
                        <div class="travel_info_tab_right"></div>
                      </div>
                    </li>
                    <li>
                      <div class="travel_info_tab_wrap">
                        <div class="travel_info_tab_left"></div>
                        <div class="travel_info_tab_center">
                          <a href="#" onmouseover="easytabs('1', '2');" onfocus="easytabs('1', '2');" onclick="return false;"
                            title="" id="tablink2"><xsl:value-of select="umbraco.library:GetDictionaryItem('About the stay')"/></a>
                        </div>
                        <div class="travel_info_tab_right"></div>
                      </div>
                    </li>
                    <li>
                      <div class="travel_info_tab_wrap">
                        <div class="travel_info_tab_left"></div>
                        <div class="travel_info_tab_center">
                          <a href="#" onmouseover="easytabs('1', '3');" onfocus="easytabs('1', '3');" onclick="return false;"
                            title="" id="tablink3"><xsl:value-of select="umbraco.library:GetDictionaryItem('About the area')"/></a>
                        </div>
                        <div class="travel_info_tab_right"></div>
                      </div>
                    </li>
                  </ul>
                </div>
                <div id="bg_textarea">
                  <div id="tabcontent1">
                    <img src="{$feedContent//AboutHotel/ProductImage/Pic40}" alt="" style="background-color: Gray; float: right; width: 136px; height: 136px; vertical-align: top; margin: 0px 5px 0px 10px;" />
                    <h3>
                      <xsl:value-of select="$feedContent//HotelInformation/HotelFacilityHeader"/>
                    </h3>
                    <p>
                      <xsl:value-of select="$feedContent//HotelInformation/HotelFacilities" disable-output-escaping="yes"/>
                    </p>
                    <br />
                    <h3>
                      <xsl:value-of select="$feedContent//HotelInformation/TilkobHeader"/>
                    </h3>
                    <p>
                      <xsl:value-of select="$feedContent//HotelInformation/Tilkob" disable-output-escaping="yes"/>
                    </p>
                    <br />
                    <h3>
                      <xsl:value-of select="$feedContent//HotelInformation/DiverseHeader"/>
                    </h3>
                    <p>
                      <xsl:value-of select="$feedContent//HotelInformation/Diverse" disable-output-escaping="yes"/>
                    </p>
                  </div>
                  <div id="tabcontent2">
                    <h3>
                      <xsl:value-of select="$feedContent//ChildDiscountHeader"/>
                    </h3>
                    <p>
                      <xsl:value-of select="$feedContent//ChildDiscount" disable-output-escaping="yes"/>
                    </p>
                    <p>
                      <xsl:value-of select="$feedContent//ChildDiscountCmt" disable-output-escaping="yes"/>
                    </p>
                    <br />
                    <h3>
                      <xsl:value-of select="$feedContent//ArrivalHeader"/>
                    </h3>
                    <p>
                      <xsl:value-of select="$feedContent//ArrivalTxt" disable-output-escaping="yes"/>
                    </p>
                  </div>
                  <div id="tabcontent3">
                    <h3>
                      <xsl:value-of select="$feedContent//AboutHotel/AreaTxt_Full/AreaTxt1"/>
                    </h3>
                    <p>
                      <xsl:value-of select="$feedContent//AboutHotel/AreaTxt_Full/AreaTxt2" disable-output-escaping="yes"/>
                    </p>
                  </div>
                </div>
                <div id="bg_textarea_dropshadow"></div>
              </div>
              <div id="content_right">
                <div id="content_booking">
                  <select name="arriveldate" id="ddList">
                    <option><xsl:value-of select="umbraco.library:GetDictionaryItem('Choose arrival date')"/></option>
                    <xsl:for-each select="$feedContent//ArrivalDates/ArrivalDate">
                      <option class="arrival_green" value="{@BookingUrl}">
                        <xsl:if test="@Status = 1">
                          <xsl:attribute name="class">arrival_yellow</xsl:attribute>
                        </xsl:if>
                        <xsl:value-of select="umbraco.library:FormatDateTime(., 'd. MMMM yyyy')"/>
                      </option>
                    </xsl:for-each>
                  </select>
                  <div id="content_booking_text">
                    <img src="/media/507671/green_dot.png" />&nbsp;<xsl:value-of select="umbraco.library:GetDictionaryItem('Arrival possible')"/><br />
                    <img src="/media/507676/yellow_dot.png" />&nbsp;<xsl:value-of select="umbraco.library:GetDictionaryItem('Answer within')"/>
                  </div>
                  <a href="">
                    <img id="orderNow_btn" src="/media/507681/bestilnu_dk.gif" />
                  </a>
                  <span id="RoomType">
                    <xsl:value-of select="$feedContent//PriceLine"/>
                  </span>
                </div>
                <div class="green_transparent_45_wrap">
                  <div id="transparent_45_top">
                  </div>
                  <div id="transparent_45_center">
                    <b>
                      <xsl:value-of select="$feedContent//YouGetHeader"/>
                    </b>
                    <br />
                    <xsl:value-of select="$feedContent//YouGet" disable-output-escaping="yes"/>
                    <div class="line">
                    </div>
                    <b>
                      <xsl:value-of select="$feedContent//TravelTypeHeader"/>
                    </b>
                    <br />
                    <xsl:value-of select="$feedContent//TravelType"/>
                    <div class="line">
                    </div>
                    <b>
                      <xsl:value-of select="$feedContent//RoomTypeHeader"/>
                    </b>
                    <br />
                    <xsl:value-of select="$feedContent//RoomType"/>
                  </div>
                  <div id="transparent_45_bund">
                  </div>
                </div>
              </div>
            </xsl:when>
            <xsl:otherwise>
              <div id="off_content_text">
                <xsl:value-of select="umbraco.library:GetDictionaryItem('The srtike is bought')" disable-output-escaping="yes"/>
                <p>
                  <b><xsl:value-of select="umbraco.library:GetDictionaryItem('About the stay')"/></b>
                  <br />
                  <xsl:value-of select="$feedContent//AboutHotel/SubHeadLine"/>
                  <br />
                  <xsl:value-of select="$feedContent//YouGet" disable-output-escaping="yes"/>
                </p>
                <br />
                <p>
                  <xsl:value-of select="umbraco.library:GetDictionaryItem('Price Only')"/>&nbsp;<xsl:value-of select="$feedContent//Price"/><xsl:value-of select="umbraco.library:GetDictionaryItem('CommaStroke')"/> &nbsp;&nbsp;&nbsp; <xsl:if test="$feedContent//SavePrice != ''"><xsl:value-of select="umbraco.library:GetDictionaryItem('Price Save')"/>&nbsp;<xsl:value-of select="$feedContent//SavePrice"/><xsl:value-of select="umbraco.library:GetDictionaryItem('CommaStroke')"/></xsl:if>
                </p>
                <p>
                  <a target="_blank">
                    <xsl:attribute name="href">
                      <xsl:value-of select="$feedContent//ProductURL"/>
                    </xsl:attribute>
                    <b><xsl:value-of select="umbraco.library:GetDictionaryItem('Read more')"/>&nbsp;<xsl:value-of select="Exslt.ExsltStrings:lowercase(umbraco.library:GetDictionaryItem('About the stay'))"/>...</b>
                  </a>
                </p>
              </div>
              <div id="off_content_right">
                  <a href="/medlem.aspx"><img src="/media/521815/banner_dk.jpg" alt=""/></a>
              </div>
            </xsl:otherwise>
          </xsl:choose>
        </div>
      </xsl:if>
    </xsl:template>
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 07, 2011 @ 16:11
    Jan Skovgaard
    0

    Haha...I sure did...:-)

    However...come to think about it...what does the first 4 lines look like? Do you have added some special entities in this part of the document?

    <!DOCTYPE xsl:stylesheet [
      <!ENTITY nbsp "&#x00A0;">
    ]>

    /Jan

  • Kasper Dyrvig 246 posts 379 karma points
    Apr 07, 2011 @ 16:19
    Kasper Dyrvig
    0

    This is it

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" mlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets">

    <xsl:output method="html" omit-xml-declaration="yes"/>
  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Apr 07, 2011 @ 16:32
    Chriztian Steinmeier
    0

    Hi Kasper,

    The error you're receiving suggests to me that the feed has some erroneous Advertiser JavaScript/HTML in it, i.e., URLs containing unescaped & signs.

    With a problem like this the 1st step you should take is to rule out ALL possibilities of a subtle error in your code causing this, and thus try something like this:

    Create a new Macro using the "Clean" template and then do only this in the root template:

    <xsl:template match="/">
        <textarea cols="45" rows="30"><xsl:copy-of select="umbraco.library:GetXmlDocumentByUrl(URL_HERE, 0)" /></textarea>
    </xsl:template>

    If that throws errors, you know it's in the feed and you can stop pulling hairs!

    /Chriztian 

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Apr 07, 2011 @ 16:36
    Chriztian Steinmeier
    1

    If that works, try the same without the textarea and see if what you got will parse as valid XML (copying from the textarea won't work, because the critical characters have been translated - copy from the raw source should work, though).

    Copy the raw XML to a new document - save as feed.xml and open in Internet Explorer - it'll complain about anything that doesn't validate.

    /Chriztian

  • Kasper Dyrvig 246 posts 379 karma points
    Apr 07, 2011 @ 16:40
    Kasper Dyrvig
    0

    I got the same error.

    So now, as you say, we are sure that the problem is the xml feed.

  • Kasper Dyrvig 246 posts 379 karma points
    Apr 07, 2011 @ 16:49
    Kasper Dyrvig
    0

    You guys write faster than I can reply... :-)

    I copied the raw xml, and there where no complains anywhere.

    <?xml version="1.0"?>
    <productinfo><productid>87181</productid></productinfo>

    In my mind the problem is moving towards the code that generates this feed.

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Apr 07, 2011 @ 20:33
    Chriztian Steinmeier
    0

    Is that the complete feed?

    If so, I guess you should try the feed URL in an HTTP application, like http://hurl.it or similar...

    Maybe the feed URL redirects to another page? That could probably explain why the library function chokes on the result...?

    /Chriztian

  • Kasper Dyrvig 246 posts 379 karma points
    Apr 08, 2011 @ 12:42
    Kasper Dyrvig
    0

    Hi

    Thanks for all your replies! Sorry I let you wait so long...

    We finally got it working! It turned out that the page with the feed couldn't handle the request becouse it was an .aspx page. After making it to a .ashx page it works perfect!

    Thanks again - See you at CodeGarden11!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 08, 2011 @ 20:07
    Jan Skovgaard
    0

    Hi Kasper

    Great to hear you managed to solve this...what a weird one! But thanks for sharing the solution. It's always good to hear how it was solved.

    But a bit strange the server could not handle the request when it was .aspx? Do you know why it could'nt?

    /Jan

  • Kasper Dyrvig 246 posts 379 karma points
    Apr 11, 2011 @ 15:48
    Kasper Dyrvig
    0

    It seams because of the aspx file extension the request wasn’t sent to the xml site at all. It got blocked within the Umbraco site itself.

Please Sign in or register to post replies

Write your reply to:

Draft