Converting ezstring to ezxml with ezchangeclass extension

Author Message

Mauro Innocenti

Tuesday 04 September 2007 7:58:43 am

I love the Modzelewski's extension "Object content class change" ( http://ez.no/community/contribs/applications/object_content_class_change ) but I need to convert a class with string attributes to another with xml blocks.
This extension provide the mechanism for converting attribute types not supported by external script (PHP code).
Anyone know what are the right eZ methods/functions to use for such conversion?

Thanks in advance...

Mauro Innocenti

Wednesday 05 September 2007 6:17:43 am

I think this is the right way to follow:
http://ez.no/community/forum/developer/urgent_how_to_generate_xml_to_insert_in_a_attribute

Olivier Ouin

Friday 14 September 2007 1:30:13 am

You can try to build a module implementing this a function like this :

    function build_xml_string($string_to_convert) {    
	 include_once( "lib/ezxml/classes/ezxml.php" );
        $doc = new eZDOMDocument( "" );

        // create the root xml node
        $root = $doc->createElementNode( "section" );			
        $doc->setRoot( $root );
        $root->appendAttribute( $doc->createAttributeNode( "xmlns:image", "http://ez.no/namespaces/ezpublish3/image/" ) );
        $root->appendAttribute( $doc->createAttributeNode( "xmlns:xhtml", "http://ez.no/namespaces/ezpublish3/xhtml/" ) );
        
        $content_paragraphs = explode ("\r\n\r\n", $string_to_convert);
        foreach ($content_paragraphs as $content_paragraph) {
	        unset( $paragraph_node );
			$paragraph_node =& $doc->createElementNode( "paragraph" );
			$content_lines = explode ("\r\n", $content_paragraph);
  			foreach ($content_lines as $content_line) {
				unset( $line_node );
				unset( $text_node );
				$line_node =& $doc->createElementNode( "line" );
				$paragraph_node->appendChild( $line_node );						
				$text_node =& $doc->createTextNode( $content_line );
				$line_node->appendChild($text_node);
			}	
			$root->appendChild( $paragraph_node );
        }
        
		$xml_string = $doc->toString();
        return $xml_string;
    }

After what you just have to retrieve the content of your linetext attributes, convert it using this function, and assign it to the data_text field of your XMLBloc attributes like this

    $xmlbloc_contentobjectattribute->setAttribute("data_text", $xml_string);

But it's a "dirty" way to do if you think about forward compatibilty, because the XML model of XMLBloc attributes can be changed in the future.
A better way to do it would be to refer to /kernel/classes/datatypes/ezxmltext/ezxmlschema.php or something like this.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.