Forums / Extensions / Converting ezstring to ezxml with ezchangeclass extension

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.

eZ debug

Timing: Jan 29 2025 13:43:49
Script start
Timing: Jan 29 2025 13:43:49
Module start 'content'
Timing: Jan 29 2025 13:43:49
Module end 'content'
Timing: Jan 29 2025 13:43:49
Script end

Main resources:

Total runtime0.1467 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 588.1875180.7969
Module start 'content' 0.00560.0070 768.984493.9922
Module end 'content' 0.01260.1341 862.9766522.4219
Script end 0.1466  1,385.3984 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00342.3166200.0002
Check MTime0.00130.8659200.0001
Mysql Total
Database connection0.00080.534910.0008
Mysqli_queries0.101268.95881410.0007
Looping result0.00140.93881390.0000
Template Total0.133590.910.1335
Template load0.00090.639910.0009
Template processing0.132590.306210.1325
Override
Cache load0.00070.444210.0007
Sytem overhead
Fetch class attribute can translate value0.00080.548110.0008
XML
Image XML parsing0.00030.182010.0003
General
dbfile0.00714.8390200.0004
String conversion0.00000.003430.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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