protected function prepareInsert($item)
{
if (empty($item)) {
return;
} elseif (is_string($item)) {
// If configured to do so, replace all entities.
if ($this->options['replace_entities']) {
$item = \QueryPath\Entities::replaceAllEntities($item);
}
$frag = $this->document->createDocumentFragment();
try {
set_error_handler(array('\\QueryPath\\ParseException', 'initializeFromError'), $this->errTypes);
$frag->appendXML($item);
} catch (Exception $e) {
restore_error_handler();
throw $e;
}
restore_error_handler();
return $frag;
} elseif ($item instanceof self) {
if ($item->size() == 0) {
return;
}
$frag = $this->document->createDocumentFragment();
foreach ($item->matches as $m) {
$frag->appendXML($item->document->saveXML($m));
}
return $frag;
} elseif ($item instanceof \DOMNode) {
if ($item->ownerDocument !== $this->document) {
// Deep clone this and attach it to this document
$item = $this->document->importNode($item, true);
}
return $item;
} elseif ($item instanceof \SimpleXMLElement) {
$element = dom_import_simplexml($item);
return $this->document->importNode($element, true);
}
// What should we do here?
//var_dump($item);
throw new \QueryPath\Exception('Cannot prepare item of unsupported type: ' . gettype($item));
}