public function MigrateItemsXML::getItemsFromXML in Migrate 7.2
Same name and namespace in other branches
- 6.2 plugins/sources/xml.inc \MigrateItemsXML::getItemsFromXML()
Parses out the items from a given XML object, and parse it's items.
Given an XML object, parse out the items for processing and return them as an array. The location of the items in the XML are based on the item xpath set in the constructor. Items from currentUrl are cached. The list of items returned from the cache except when this is the first call (ie, cache is NULL) OR the refresh parameter is TRUE.
Items are cached as an array of key=ID and value=stdClass object with attribute xml containing the xml SimpleXMLElement object of the item.
Parameters
SimpleXMLElement $xml: XML to parse
bool $refresh: Indicates if necessary parse again the items or get them from cache.
Return value
array Array of obtained items.
1 call to MigrateItemsXML::getItemsFromXML()
- MigrateItemsXML::getAllItems in plugins/
sources/ xml.inc - Load the XML at the given URL, and return an array.
File
- plugins/
sources/ xml.inc, line 733 - Support for migration from XML sources.
Class
- MigrateItemsXML
- Implementation of MigrateItems, for providing a list of IDs and for retrieving a parsed XML document given an ID from this list.
Code
public function getItemsFromXML(SimpleXMLElement $xml, $refresh = FALSE) {
if ($refresh !== FALSE && $this->currentItems != NULL) {
return $this->currentItems;
}
$this->currentItems = NULL;
$items = array();
$result = $xml
->xpath($this->itemXpath);
if ($result) {
foreach ($result as $item_xml) {
if (!isset($item_xml)) {
continue;
}
// Namespaces must be reapplied after xpath().
$this
->registerNamespaces($item_xml);
$id = $this
->getItemID($item_xml);
$item = new stdclass();
$item->xml = $item_xml;
$items[$id] = $item;
}
$this->currentItems = $items;
return $this->currentItems;
}
else {
return NULL;
}
}