} } $elements = array("title_{$lang}" => 'title', 'catalogentry' => 'identifier', 'catalog' => 'remoteid', 'language' => 'lang', "description_{$lang}" => 'description', "keyword_{$lang}" => 'keywords', 'contributor' => 'Contributor', 'issuedate' => 'IssueDate', 'agefrom' => 'AgeFrom', 'ageto' => 'AgeTo', 'format' => 'mimetype', 'location' => 'url', 'file' => 'file', 'learningresourcetype' => 'LearningResourceType', 'rights' => 'Rights', 'rightsdescription' => 'RightsDescription', 'classificationpurpose' => 'ClassificationPurpose', 'classificationtaxonpath' => 'ClassificationTaxonPath'); $xml = simplexml_load_file($file); if ($result = $xml->xpath("doc")) { foreach ($result as $doc) { // check if the entry exists $exists = false; if ($el = $doc->xpath("field[@name='catalogentry']/text()")) { $identifier = $el[0]; } if (!($entry = taoresource_entry::get_by_identifier($identifier))) { $entry = new taoresource_entry(); } else { $entry->metadata_elements = array(); $exists = true; } $entry->add_element('type', 'file'); foreach ($elements as $key => $element) { if ($el = $doc->xpath("field[@name='{$key}']/text()")) { $entry->add_element($element, $el[0]); } } if ($exists) { $entry->update_instance(); } else { $entry->add_instance(); } } } exit(0);