0

I have some data of type Images where I want to import in the format of xml named 'images.xml' which containing images url and information.

I want to import this file programatically using feeds API.

How can I achieve this?

for this i use following code:

$source = feeds_source($importerId);
$config = array(
  'fetcher' => array(
    'plugin_key' => 'FeedsHTTPFetcher',
    'config' => array(
      'auto_detect_feeds' => FALSE,
      'use_pubsubhubbub' => FALSE,
      'designated_hub' => '',
      'request_timeout' => NULL,
      ),
    ),
  'parser' => array(
    'plugin_key' => 'FeedsXPathParserXML',
    'config' => array(
      'sources' => array(
        'xpathparser:0' => 'url',
        ),
      'rawXML' => array(
        'xpathparser:0' => 'xpathparser:0',
        ),
      'context' => '//image',
      'exp' => array(
        'errors' => 0,
        'debug' => array(
          'context' => 0,
          'xpathparser:0' => 0,
          ),
        ),
      'allow_override' => 1,
      ),
    ),
  'processor' => array(
    'plugin_key' => 'FeedsNodeProcessor',
    'config' => array(
      'expire' => '-1',
      'author' => 0,
      'authorize' => 1,
      'mappings' => array(
        0 => array(
          'source' => 'xpathparser:0',
          'target' => 'url',
          'unique' => FALSE,
          ),
        ),
      'update_existing' => '0',
      'input_format' => 'full_html',
      'skip_hash_check' => 0,
      'bundle' => 'images',
      ),
    ),
  'content_type' => 'images',
  'type' => 'images',
  'update' => 0,
  'import_period' => '-1',
  'expire_period' => 3600,
  'import_on_create' => 1,
  'process_in_background' => 0,
  );
$source->importer->addConfig($config);

$featcher_config = $source->getConfigFor($source->importer->fetcher);
$featcher_config['source'] = $url;
$source->setConfigFor($source->importer->fetcher, $featcher_config);
//$source->save();
//node_save($source);
$source->startImport();

But this code show "Download of failed with code -1002" and no images are import...

4
  • can you please add some details that what exactly you have already tried and not worked for you, so anybody can provide solution. Commented Dec 5, 2014 at 6:57
  • I think you can't understand what you want to do or I think you are not able to clarify your question. Clarify your question to understand.
    – Nishant
    Commented Dec 5, 2014 at 8:02
  • I think you have some data of type images & you have a view where images are shown. And you want to fetch the image data in the format of 'xml'. Am I right ?
    – Nishant
    Commented Dec 5, 2014 at 8:03
  • Have you tried Feeds extensible parsers? They have XPath & QueryPath parsers for importing XML with the Feeds module.
    – Jelle
    Commented Dec 5, 2014 at 9:28

2 Answers 2

1

It depends somewhat on your use case. For example are you scraping the images off a web page or are you using a direct image file URL.

If you are scraping from a web page you can use the feeds image grabber module.

That module provides additional settings where you can configure a CSS selector for the page that is in your XML file.

The module will then request that page and scrape the image from it based on the selector you configured then add the image to the imported item.

0

IF you are getting those images from a website using a XML format. Use the SimplePie Core parser.The parser will allow you to get the images with their URL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.