Samuli Natri
Oct. 10, 2016
Updated: Oct. 24, 2016
0
By Samuli NatriOct. 10, 2016
(Updated: Oct. 24, 2016)
0

Drupal 7 Tutorial : XML To Nodes With Feeds Module (Article + Video)

How to Import XML data as nodes with Feeds and Feeds Ex modules.

How to install it?

drush -y en feeds feeds_ex feeds_ui

Feeds Ex module provides the XML Parser. Make sure you enable the Feeds Admin module (feeds_ui).

Import data from XML as nodes

  • We are going to use this xml file as data source:
<books>
  <book>
    <title>War and Peace</title>
    <author>Leo Tolstoi</author>
    <description>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    </description>
  </book>
  <book>
    <title>Waking Up</title>
    <author>Sam Harris</author>
    <description>Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    </description>
  </book>
</books>
  • Create a content type called book
  • Save and add fields
  • Add Author text field with the default settings:

  • Go to Structure > Feeds Importers > Add Importer

  • Add Importer and name it Book

Basic Settings

  • Turn off periodic import:

Attach to content type setting allows us to import source when a specific type of node is created. With 'Use standalone form' we have a form to import the data.

Remember to Save each section before you move to the next!

Fetcher

  • Select a File upload as the fetcher:

  • Leave File upload settings as they are:

Parser

  • Select XML Xpath as the parser:

  • Set the parser settings.
  • Values in the VALUE column has to match the names of the XML tags in the source file.
  • Define /books/book as the context:

Processor

  • Leave processor as node:

  • Select Bundle as Book
  • Select Update existing nodes:

 

  • Use administer account for the Author:

  • Finally map the source data to the destination fields.
  • SOURCE column has the sources we defined previously and TARGET column describes the target fields in the Book content type.

Make sure you define one target as unique!

  • 2 nodes will be created:

Update nodes

  • Change the data file and upload it again:
<books>
  <book>
    <title>War and Peace</title>
    <author>Leo Tolstoi</author>
    <description>Lorem CHANGED DATA ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    </description>
  </book>
  <book>
    <title>Waking Up</title>
    <author>Sam Harris</author>
    <description>Consectetur CHANGED DATA adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    </description>
  </book>
  <book>
    <title>Hitch-22</title>
    <author>Christopher Hitchens</author>
    <description>Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    </description>
  </book>
</books>
  • And we have 1 new node + 2 updated nodes:

Links

https://www.drupal.org/project/feeds

https://www.drupal.org/project/feeds_ex

Add new comment