This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » Extensions » Converting ezstring to ezxml with...

Converting ezstring to ezxml with ezchangeclass extension

Converting ezstring to ezxml with ezchangeclass extension

Tuesday 04 September 2007 4:58:43 pm - 2 replies

I love the Modzelewski's extension "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...

Modified on Thursday 06 September 2007 9:30:08 am by Mauro Innocenti

Wednesday 05 September 2007 3:17:43 pm

I think this is the right way to follow:

Modified on Wednesday 05 September 2007 3:17:53 pm by Mauro Innocenti

Friday 14 September 2007 10: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", "" ) );
        $root->appendAttribute( $doc->createAttributeNode( "xmlns: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 );
			$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.


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from