You are here

protected function MigrateListXML::getIDsFromXML in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 plugins/sources/xml.inc \MigrateListXML::getIDsFromXML()

Gets an array of the IDs found in a XML.

Given an XML object, parse out the IDs for processing and return them as an array. The default implementation assumes the IDs are simply the values of the top-level elements - in most cases, you will need to override this to reflect your particular XML structure.

Parameters

SimpleXMLElement $xml: Object from we get the ID's

Return value

array Extracted ID's

1 call to MigrateListXML::getIDsFromXML()
MigrateListXML::getIdList in plugins/sources/xml.inc
Load the XML at the given URL, and return an array of the IDs found within it.

File

plugins/sources/xml.inc, line 104
Support for migration from XML sources.

Class

MigrateListXML
Implementation of MigrateList, for retrieving a list of IDs to be migrated from an XML document.

Code

protected function getIDsFromXML(SimpleXMLElement $xml) {
  $ids = array();
  foreach ($xml as $element) {
    $ids[] = (string) $element;
  }

  // Additionally, if there are any namespaces registered, try to parse
  // elements with namespaces as well.
  if ($namespaces = $xml
    ->getNamespaces()) {
    foreach ($namespaces as $prefix => $url) {
      foreach ($xml
        ->children($url) as $element) {
        $ids[] = (string) $element;
      }
    }
  }
  return array_unique($ids);
}