i'm dealing with a (remote) xml import and i noticed something.
since my xml is an atom one, the root <feed> tag has attributes (something like this <feed xmlns="http://www.w3.org/2005/Atom">) and it doesn't work.

so i've investigated a little bit.
i downloaded the xml and i stripped all the attributes... it worked!
so my conclusion is that the xpath /feed/item (and, probably, other tags too) doesn't work properly if it has to deal with attributes.

i saw other migrate issues talking about tag attributes (this one, for example)... am i missing something?
thanks a lot.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeryan’s picture

Title: xml atom feed » Get data from all XML namespaces
Category: support » feature

What we're talking about here aren't attributes per se but namespaces. The PHP XML APIs we use require, in the presence of namespaces, that the content in elements from those namespaces be separately fetched. The WordPress Migrate module deals with this by overriding the MigrateXMLReader class to explicitly fetch those elements - see wordpress_source.inc.

Looking at that now, I don't see why Migrate's source class can't do this automatically - changing to a feature request.

windmaomao’s picture

Based on xml import implemented by Migrate module, it's pretty solid. What we need is an additional command similar like the following,

    $this->addFieldMapping('field_latest_link', 'link')
         ->xpath('link');   // or xpath('atom:link')
         ->namespace('atom');

currently the code won't work, since atom:link is in non-default namespace.

A similar approach is done by #11 on https://drupal.org/node/1336880. I want to do something similar, but i guess it might be more specific if we can do per field basis.

cruno’s picture

I get this error:

Migration failed with source plugin exception: Passed variable is not an array or object, using empty array instead
with MigrateItemsXML and using namespaces with the XML file.

I tried applying the patch linked here, got errors applying since it's a different version of the codebase, and ended up manually applying the patch. I'm still getting this error and am currently trying to track down where the error is being thrown.
It's definitely having issues with namespaces in XML. Has anyone been able to fix this issue?

I've created a more detailed post on the Drupal stack exchange forum that may help break down the underlying cause, or at least get closer to the issue.

cruno’s picture

I've re-rolled the patch stated above. There were a couple of issues that I have pointed out here.

Status: Needs review » Needs work

The last submitted patch, 4: migrate_namespace_prefix_xml-1961316-4.patch, failed testing.

maciej.zgadzaj’s picture

Version: 7.x-2.5 » 7.x-2.x-dev
Status: Needs work » Needs review
FileSize
3.42 KB

Here is the patch from #4 re-rolled for the most recent dev version, also including 2 extra small changes:
- removed call to $this->registerNamespaces($xml); from MigrateListXML::getIdList(), as it was not available from there, and wouldn't work - so still needs to be implemented
- fixed check of return value of simplexml_load_file() in MigrateItemsXML::xml()

Again, please note, this patch is not a complete solution - it fixes namespace handling for MigrateSourceMultiItems (where MigrateItemsXML class is used as source items class), but still needs to be done for MigrateSourceList.

Let's see what bot says...

13rac1’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Bot likes it! A new feature like this should include updates to the tests too.

maciej.zgadzaj’s picture

Status: Needs work » Needs review
FileSize
34.32 KB

So, following up on #6, here comes another patch - this time the list of changes got pretty long, and should be fully comprehensive:

  • added namespace support to MigrateListXML, MigrateItemXML, MigrateItemsXML and MigrateSourceXML classes
  • fixed XML element validation in MigrateXMLReader
  • added new migrations from XML files with namespaces to migrate_example module: WineProducerNamespaceXML, WineProducerMultiNamespaceXML and WineProducerNamespaceXMLPull
  • added relevant XML files with namespaces: index2.xml, 0002.xml, producers3.xml and producers4.xml
  • added missing XML migrations to MigrateXMLUnitTest: WineProducerXML, WineProducerMultiXML and WineProducerXMLPull
  • added new XML with namespaces migrations to MigrateXMLUnitTest: WineProducerNamespaceXML, WineProducerMultiNamespaceXML and WineProducerNamespaceXMLPull

Bot? U like?

  • Commit 8355def on 7.x-2.x by mikeryan:
    Issue #1961316 by TwoD, cruno, maciej.zgadzaj: Get data from all XML...
mikeryan’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests +Migrate 2.6

Committed, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.