I'm pulling an XML feed which includes link rel="alternate" tags, however these don't seem to get parsed by the XML importer into the body of the feed type. Am I missing something?

Comments

natew’s picture

Component: Feeds Import » Code
Issue summary: View changes
StatusFileSize
new812 bytes

I have an atom 1.0 feed and I am using feeds to create nodes with the content. When I import from this feed all the imported links go to pages that do not exist. After a little investigation into the feed all the entry links are relative and use the rel="alternate" attribute.

I looked into the code for the Atom 1.0 Common syndication parser. it looks like there is code for handling the rel="alternate" links however the base path was not being set for me. The base path in my feed is in one of the link elements in the feed element (again with rel="alternate"). Attached is a patch that sets the base path (if not already set) to the href in the feed link with rel="alternate". This fixed my issue, however I am not sure if this is the correct approach or I am missing something?

natew’s picture

Version: 7.x-2.0-alpha4 » 7.x-2.0-alpha8
Priority: Major » Normal
natew’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: feeds-linkrelalternate-1281496-1.patch, failed testing.

twistor’s picture

Version: 7.x-2.0-alpha8 » 7.x-2.x-dev
Status: Needs work » Needs review

twistor’s picture

Can you share the link to this feed?

natew’s picture

megachriz’s picture

StatusFileSize
new72.71 KB

I checked the feed with my Feeds import preview module. This is a preview of the parsed result using the common syndication parser on the latest dev:

The item's <link rel="alternate"> is parsed to the source "url". It looks like the issue here is that the url is taking "literally", the parsed result for url is for example: jobposting.do?pcd=YT&amp;wid=pv&amp;sort=D&amp;id=17385559&amp;source=rss, thus without a leading "http://www.example.com", which makes the url not very useful when it is displayed just like that. Am I right that is what the issue is about?

natew’s picture

Yeap, that is exactly the issue I ran into. Thank you for looking into this.

twistor’s picture

Category: Bug report » Feature request
StatusFileSize
new5.46 KB

I'm not sure about this. Here's a patch, since current link handling is a bit broken, this patch makes a few more changes.

That said, this feed is broken, so it's not really a bug. The rel="alternate" is not supposed to be used as a base url. If anything, it should be the URL we downloaded the feed from, but since we don't have that, the rel="self" should be used.

natew’s picture

I reverted my patch from #1 and applied your patch from #11 on the alpha 8 release of feeds and the feed items don't seem to import. I went to the latest dev version (from yesterday) and verified the feed imports. I then applied the patch from #11 and recreated the feed. I got a while bunch of warnings.:
Serialization of 'SimpleXMLElement' is not allowed and a message that 75 items couldn't be imported.

twistor’s picture

Issue tags: +Needs tests
StatusFileSize
new820 bytes
new5.66 KB

Probably missed a string cast somewhere.

natew’s picture

Thanks twistor, I just tried the latest patch and this works for me. The feed items get imported and the proper url is set.

I also wanted to mention that I agree about this feed being most likely broken. However the entries links do get parsed correctly and work in other "feed browsers" like firefox. So I think your solution will work. :)

Thanks again for looking into this and providing a solution!

natew’s picture

StatusFileSize
new5.5 KB

Re-spin the patch for feeds 7.x-2.0-beta2.

megachriz’s picture

And now with an automated test! The first patch only includes the test and should fail. The second patch should pass tests. Let's see if that happens...

Note that I used content from this issue as test content :). You will be part of the history of Feeds, natew!

The last submitted patch, 16: feeds-base-url-1281496-16-tests-only.patch, failed testing.

  • MegaChriz committed df1afad on 7.x-2.x authored by twistor
    Issue #1281496 by twistor, MegaChriz, natew: fixed prepend base url for...
megachriz’s picture

Status: Needs review » Fixed

Committed #16 with a small change in the following code:

+++ b/libraries/common_syndication_parser.inc
@@ -201,17 +181,32 @@ function _parser_common_syndication_atom10_parse($feed_XML) {
+    if (!$item['url'] && !empty($news->content['src']) && valid_url($news->content['src'], TRUE)) {
+      $item['url'] = (string) $new->content['src'];
     }

Changed $new->content['src'] to $news->content['src'].

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.