Feeds with Xpath Parser won’t import images using image URL in XML file

Importing images into a multi-valued image field using image URLs from an XML file is not working for me. The Xpath Parser debug output shows the multiple image URLs being parsed correctly, but the images don’t get imported. No problem with other ordinary fields.

The XML structure is:

<units>   <unit>     <unit_details>       <images>         <image>           <uri>              http://www.example.com/files/content/villa-102-1.jpg           </uri>         </image>         <image>           <uri>              http://www.example.com/files/content/villa-102-2.jpg           </uri>         </image>       </images>     </unit_details>   </unit> </units> 

The context is: //unit

The Xpath query for the image field is: unit_details/images/image/uri

I played around with the image grabber module for feeds, but it failed also – doesn’t seem suited to this task.

  1. Is it possible to import images using the image URL from the XML file?
  2. Is it possible to import multiple images into a multi-valued image field?

I’m using Feeds version 6.x-1.0-beta12+18-dev, and Feeds Xpath Parser version 6.x-1.12


UPDATE:

I was able to import images using the CSV importer and the image URL, so this appears to be a problem with Xpath Parser.


UPDATE 2:

I’m seeing no errors in the dblog or the server log. That patch is for D7. The images do not show up in the node display, but the other fields do.

Looks like the “enclosure” error gets thrown if the local file name isn’t in the right form, but I just have an external URL. As I mentioned above, the image with the same URL does get imported using the CSV parser, so it doesn’t appear to be a problem with the Feeds module, just the Xpath Parser.

The relevant code in D6 (FeedsParser.inc) is:

    /**        * @return        *   A path pointing to a file containing the resource referenced by the        *   enclosure. This method downloads the resource if it is not local. The        *   file path must be considered temporary and is only valid for the current        *   page load.        *        * @todo Get file extension from mime_type.        * @todo This is not concurrency safe.        */       public function getFile() {         if (empty($this->file) && $this->getValue()) {           // Check if this enclosure contains a local file.           if (!parse_url($this->getValue(), PHP_URL_SCHEME)) {             if (file_check_location($this->getValue(), file_directory_path()) || file_check_location($this->getValue(), file_directory_temp())) {               if (file_exists($this->getValue())) {                 $this->file = $this->getValue();                 return $this->file;               }             }             throw new Exception(t('Invalid enclosure %enclosure', array('%enclosure' => $this->getValue())));           }           $filename = basename($this->getValue());           if (module_exists('transliteration')) {             require_once drupal_get_path('module', 'transliteration') . '/transliteration.inc';             $filename = transliteration_clean_filename($filename);           }           $dest = file_destination(file_directory_temp() .'/'. $filename, FILE_EXISTS_RENAME);           if (ini_get('allow_url_fopen')) {             $this->file = copy($this->getValue(), $dest) ? $dest : 0;           }           else {             $this->file = file_save_data($this->getContent(), $dest);           }           if ($this->file === 0) {             throw new Exception(t('Cannot write content to %dest', array('%dest' => $dest)));           }           $this->delete_file = TRUE;         }         return $this->file;       }  } 
Sponsored by SupremePR
This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Feeds with Xpath Parser won’t import images using image URL in XML file

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.