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.

eZ debug

Timing: Jan 31 2025 00:28:34
Script start
Timing: Jan 31 2025 00:28:34
Module start 'layout'
Timing: Jan 31 2025 00:28:34
Module start 'content'
Timing: Jan 31 2025 00:28:34
Module end 'content'
Timing: Jan 31 2025 00:28:34
Script end

Main resources:

Total runtime0.0267 sec
Peak memory usage8,192.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0049 588.3906151.2422
Module start 'layout' 0.00500.0042 739.6328220.7500
Module start 'content' 0.00920.0156 960.3828997.8828
Module end 'content' 0.02480.0018 1,958.265633.9922
Script end 0.0266  1,992.2578 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002910.8833140.0002
Check MTime0.00114.2775140.0001
Mysql Total
Database connection0.00082.814110.0008
Mysqli_queries0.00238.715130.0008
Looping result0.00000.055510.0000
Template Total0.00135.010.0013
Template load0.00103.857110.0010
Template processing0.00031.133310.0003
Override
Cache load0.00072.765810.0007
General
dbfile0.00145.350080.0002
String conversion0.00000.026840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs