Thursday 27 September 2007 1:54:25 am
Actually, for this latter project, I'm importing XML data (not HTML), and since code originally proposed seemed to work (except for the links) I decided to stick with it. I did, however, manage to modify it in order to add the appropriate entries in ezurl_object_link. Here's the modified version:
function setEZXMLAttribute( &$contentObjectAttribute, &$attributeContent)
{
include_once( 'kernel/classes/datatypes/ezxmltext/handlers/input/ezsimplifiedxmlinputparser.php' );
$contentObjectID = $contentObjectAttribute->attribute('contentobject_id');
$parser = new eZSimplifiedXMLInputParser( $contentObjectID, false, 0 );
$document = $parser->process($attributeContent);
if (!is_object($document))
{
$this->messages[] = $this->message("Error", "Adding creating EZXMLText");
return false;
}
// get links
$links =& $document->elementsByName( 'link' );
// for each link
foreach($links as $link)
{
// create link between url (link) and object
$eZURLObjectLink = eZURLObjectLink::create( $link->attributeValue('url_id'),
$contentObjectAttribute->attribute('id'),
$contentObjectAttribute->attribute('version') );
$eZURLObjectLink->store();
}
$domString = eZXMLTextType::domString( $document );
$contentObjectAttribute->setAttribute( 'data_text', $domString );
$contentObjectAttribute->store();
}
For those of you following pike's example, please note that the example he refers to is from 2003 and that I belive there has been some changes in the kernel since then. Among them is the attribute name of link ids (previously 'id', now 'url_id').
Sincerely,
Eirik Alfstad Johansen
http://www.netmaking.no/
|