Wednesday 19 November 2003 2:07:50 am
Its a little more complicated because the string has to be valid xml for the field to work properly. Heres a code snippet i use to add some a string and some comments. Hope it makes sense :) paul -----
$contentObjectAttribute =& $contentObjectAttributes[$key];
$contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();
if ($contentClassAttribute->attribute("name") == "My attribute")
{ $xml = new eZXML();
// Retain the current content of the attribute.
$presentContent=$contentObjectAttribute->attribute("data_text");
// Prepare the original xml for new information.
if ($presentContent != "")
{
// Turn this content into a dom tree so we can add to it.
$originalDomTree =& $xml->domTree( $presentContent );
$originalRoot =& $originalDomTree->root();
$commentSeperator =& $originalDomTree->createElementNode( "paragraph" );
$emphasizeDomNode =& $originalDomTree->createElementNode( "emphasize" ); $emphasizeDomNode->appendChild( $originalDomTree->createTextNode( "------- Additional Comment -----------" ) ); $commentSeperator->appendChild($emphasizeDomNode);
$originalRoot->appendChild( $commentSeperator );
}
// Now re-set the attribute with our new comments. Comments
// contains new xml
$contentObjectAttribute->setAttribute("data_text", $comments);
// Turn the new comments into xml by invoking the ez parsing routines.
$xmlText = new eZXMLText( eZXMLTextType::rawXMLText( $contentObjectAttribute ), $contentObjectAttribute );
$input =& $xmlText->attribute( 'input' ); $isValid = $input->validateInput( $http, "ContentObjectAttribute", $contentObjectAttribute );
// Create a new tree with our newly formed xml.
$newDomTree =& $xml->domTree( $contentObjectAttribute->attribute("data_text") );
$newRoot =& $newDomTree->root();
// First determine whether we should store the new or original xml.
// Add the new children to the original xml.
if ($presentContent != "")
{
if ($newRoot->hasChildren())
{
$rootChildren =& $newRoot->children();
foreach($rootChildren as $child)
{
$originalRoot->appendChild( $child );
} }
$contentObjectAttribute->setAttribute("data_text", $originalDomTree->toString());
}
else
{
$contentObjectAttribute->setAttribute("data_text", $newDomTree->toString()); }
|