[Drupal] How to create a feed importer and select the Fetcher as HTTP Fetcher?

| | 2 min read

I had a requirement in one of my Drupal site in which I want to import content from an external XML file generated from another website.
The XML generated as a URL say For ex: http://example.com/feed.xml, I want to fetch the XML every time from the above generated URL. Follow the below steps to fetch the XML from URL's:

Use the following modules to import feeds
Feeds
Feeds XPath Parser

After enabling modules, create a feed importer for the particular content type

Following is the steps to create feed importer:
1. Set attach to content type as standalone form (refer image1).
image1.png
2. Select fetcher as HTTP Fetcher
3. Select the parser XPath XML parser(select which one you want ,here am using XPath XML parser) refer image2.
image2.png
4. Select a processor eg: Node processor
5. Save the settings for Node processor (refer image3).
image3.png
a) Select bundle as which content type you need to import (eg: page).
b) Set all other options their about the expiration, updating < author.

6. Then create the mapping (refer image4).
image4.png
a) select xpath parser and mapping field of the content type

  • xpathparser:0 as GUID
  • xpathparser:1 As Title
  • xpathparser:2 as URL

b) Set GUID field as unique(note: you can use any other fields also as unique like email)
7. Map the settings for XPath XML parser(refer image5).
image5_0.png

for example
XML :

<?xml version="1.0" encoding="utf-8"?>
 <pages>
  <page>
   <id>1</id>
   <title>Title-1</title>
   <url>http://example.com/title1.xml</url>
  </page>
  <page>
   <id>2</id>
   <title>Title-2</title>
   <url>http://example.com/title2.xml</url>
  </page>
 </pages>

So the mapping should like
Context : //page
GUID : id
Title : title
URL : URL

That it , now you can import the data via, http://example.com/import (refer image6).
image6.png

Note :
a) please give the URL where XML exist in importer
b) The id in the above XML should be unique