Link to my previous question, which has info on data structure etc.

Now I've gotten my XML read into Migrate and content type and fields set up right (I think), but now I can't get the nodes to save. The import has the correct number of nodes, but they don't ever get imported. The wine examples in the documentation didn't say anything about using prepareRow() or anything when you are using XML. Where are my nodes? Can I pull out that data with Views even if nodes don't import? My end use for this is to arrange everything with Views.


Here is my class:


class ItemNodeMigration extends XMLMigration {
public function __construct() {
parent::__construct(MigrateGroup::getInstance('itemnode', array('default')));
$this->description = t('Grab data in XML');

// There isn't a consistent way to automatically identify appropriate "fields"
// from an XML feed, so we pass an explicit list of source fields
$fields = array(
   'id' => 'ID',
   'type' => t('Description of producer'),
   'Owner' => t('Owner'),
   'Text' => t('Text'),
   'modifiedAt' => 'Date last changed',

$this->map = new MigrateSQLMap($this->machineName,
    'id' => array(
      'type' => 'varchar',
      'length' => 6,
      'not null' => TRUE,

// This can also be an URL instead of a file path.
$xml_folder = 'http://example.com/item/';
$list_url = 'http://example.com/CompanyID/Items.xml';
// Each ID retrieved from the list URL will be plugged into :id in the
// item URL to fetch the specific objects.
$item_url = $xml_folder . ':id/desc.xml';

$this->source = new MigrateSourceList(new MigrateListXML($list_url),
  new MigrateItemXML($item_url), $fields);

$this->destination = new MigrateDestinationNode('migrate_module_itemnode');

$this->addFieldMapping('id', 'id')
$this->addFieldMapping('body', 'Text')
$this->addFieldMapping('type', 'type')
$this->addFieldMapping('owner', 'Owner')
$this->addFieldMapping('created', 'modifiedAt')


EDIT2: I have determined that my problem lies here:

    $this->map = new MigrateSQLMap($this->machineName,
                 'id' => array(
                 'type' => 'varchar',
                 'length' => 6,
                 'not null' => TRUE,

This isn't correctly mapping to my source's ID, which lies at Item/@id. How can I correct this?

  • show us your migrate class, you should just need to setup a proper MigrateDestination value. Such as MigrateDestinationNode, or MigrateDestinationEntity, or MigrateDestinationTable. – tenken Jan 15 '13 at 21:13
  • Aha. So I think the problem is that my ListXML file has the IDs I need to grab at /Example/Item/@id, and I am not accessing the ID as I need to, and that's what's keeping the files from importing as nodes. Do I have to write another source handler or something? – dodododo Jan 16 '13 at 7:03

As per this issue -- I think you need to tell MigrateSourceList where your item id's are, as an example (from isssue):

    // As with MigrateSourceMultiItems, this applies where there is not a separate
    // list of IDs to process - the source XML file is entirely self-contained.
    // For the ID path, and xpath for each component, we can use the full xpath
    // syntax as usual. However, the syntax to select the elements that correspond
    // to objects to import is more limited. It must be a fully-qualified path
    // to the element (i.e., /producers/producer rather than just //producer).
//  $item_xpath = '/producers/producer';  // relative to document
    $item_xpath = '/FMPXMLRESULT/RESULTSET/ROW';
//  $item_ID_xpath = 'sourceid';          // relative to item_xpath
    $item_ID_xpath = 'COL[1]/DATA';

    $this->source = new MigrateSourceXML($items_url, $item_xpath, $item_ID_xpath,

You only have 3 values in your constructor. I haven't done alot with migrating XML (just CSV and SQL). This issue is for D7 -- I think it should apply to D6.

  • That's what I had to do. I made a clone of MigrateSourceList where it could look inside of Item for /@id and problem was solved. – dodododo Jan 20 '13 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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