Copied to clipboard

Flag this post as spam?

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


  • Rich Green 2246 posts 4008 karma points
    Aug 31, 2010 @ 11:26
    Rich Green
    0

    Reading feed with broken namespace....

    I'm trying to read the following feed http://bit.ly/a68pDu with umbraco.library:GetXmlDocumentByUrl

    However the namespace specified in the doc does not seem to be working and therefore the GetXmlDocumentByUrl call fails.

    I've not got a response from the sites developers about getting it fixed so need a workaround.

    Any ideas?

    Thanks, Rich

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 31, 2010 @ 11:36
    Lee Kelleher
    0

    Hi Rich,

    I have just tried to load in the RSS using GetXmlDocumentByUrl and it works fine.  However I did a simple quick-n-dirty output:

    <xmp>
        <xsl:copy-of select="umbraco.library:GetXmlDocumentByUrl('http://www.ttrworldtour.com/ranking/mens-ranking-list/mens-ranking.xml')" />
    </xmp>

    I'm thinking that the problem is with the default namespace (xmlns="http://backend.userland.com/rss2") ... which you'll need to declare in your XSLT - you can give it whatever prefix you like.

    <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:rss2="http://backend.userland.com/rss2"
        exclude-result-prefixes="msxml umbraco.library rss2">

    Then you'll need to reference the XML with the namespace prefix.  i.e. <xsl:value-of select="rss2:title" />

    I can show more examples if you need?

    Cheers, Lee.

  • Rich Green 2246 posts 4008 karma points
    Aug 31, 2010 @ 11:55
    Rich Green
    0

    Hey Lee,

    Thanks for looking into it, you're right, the feed does read in however I cannot iterate through the items

    <xsl:if test="count($feedContent) &gt; 0">
        <xsl:for-each select="$feedContent//item">
    
            Never gets here
    
        </xsl:for-each>
    <xsl:if>

     

    Which I assumed was due to the namespace, how would I iterate through the loop using your example?

    Many thanks

    Rich

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 31, 2010 @ 11:58
    Lee Kelleher
    0

    Hi Rich,

    Because the RSS has a namespace associated with it at root level, all references to the XML elements will need to reference that namespace. So if you've declared the namespace (as I posted earlier), you'll need to do this...

    <xsl:if test="count($feedContent) &gt; 0">
            <xsl:for-each select="$feedContent//rss2:item">
    
                    Never gets here
    
            </xsl:for-each>
    <xsl:if>

    Literally prefixing all the elements you need with "rss2:"

    Cheers, Lee.

  • Rich Green 2246 posts 4008 karma points
    Aug 31, 2010 @ 12:09
    Rich Green
    0

    Lee, you're a genius!

    So was the namespace thing a red herring?

    The only issue now is trying to read the following value:

    <ttrRiderRanking:name>rider name</ttrRiderRanking:name>

    As the following causes an error

    <xsl:value-of select="rss2:ttrRiderRanking:name"/>

    Cheers

    Rich

     

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 31, 2010 @ 12:14
    Lee Kelleher
    1

    Hi Rich,

    Not the "trrRiderRanking" is its own namespace, so will need to be treated separately.  Add it to the namespace declarations too.

    <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:rss2="http://backend.userland.com/rss2"
            xmlns:ttrRiderRanking="http://www.ttrworldtour.com/ns/ttrRiderRanking"
            exclude-result-prefixes="msxml umbraco.library rss2 ttrRiderRanking">

    Then reference any of those elements with the namespace prefix:

    <xsl:value-of select="ttrRiderRanking:name"/>

    Cheers, Lee.

  • Rich Green 2246 posts 4008 karma points
    Aug 31, 2010 @ 12:16
    Rich Green
    0

    Cheers Lee, you're a star.

    Rich

  • dillorscroft 198 posts 192 karma points
    Jun 01, 2011 @ 16:50
    dillorscroft
    0

    I've a very similar issue when trying to parse a feed containing a specific namespace.  obs

    I've added the namespace in the XSLT and the feed works fine for standard namespace elements such as title and pubdate but as soon as I try to access obs:moredetail I get absolutely nothing.

    I've spent a good few hours on this and I'm tearing my hair out.

    I can even dump the full XML to a textarea and see the feed but can not access the obs namespace items 

    Any thoughts?


    DC

  • dillorscroft 198 posts 192 karma points
    Jun 01, 2011 @ 16:55
    dillorscroft
    1

    Typical.  As soon as I post on here I figured it out.  The namespace urn was incorrect.  I took it from the docs though which were wrong!

Please Sign in or register to post replies

Write your reply to:

Draft