How to render an XML Block into XHTML (PHP script)

Author Message

Hakim Bouras

Wednesday 27 May 2009 11:58:38 pm

Hi,

I am building a light newsletter feature. The body of the newsletter is contained in an XML Block attribute of an eZ object.

In my PHP client script, how can I render this XML Block into XHTML (used in the emails body) ?

<i>(I need somehow the equivalent of the template operator attribute_view_gui attribute=xml_block_body)</i>

Also would you have an idea how to convert the XHTML to plain text ?

Thanks
Hakim

Damien Pobel

Wednesday 03 June 2009 3:20:52 am

Hi Hakim,

To get the XHTML output of an XML Block attribute, you can write something like :

$dataMap = $node->attribute( 'data_map' );
$output = $dataMap['your_attribute_identifier']->attribute( 'content' )->attribute( 'output' );
$xhtml = $ouput->attribute( 'output_text' );

And to convert the XHTML to plain text, you can use the strip_tags PHP function [1]

[1] http://php.net/strip_tags

Damien
Planet eZ Publish.fr : http://www.planet-ezpublish.fr
Certification : http://auth.ez.no/certification/verify/372448
Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish

Hakim Bouras

Thursday 04 June 2009 4:38:24 am

Hi Damien,

Thanks a lot for your help.

Actually I had to change a small thing to make it work : to use the method "outputText()" instead of the attribute "output" (but this is maybe due to the fact I am using a version 4.1).

$output = $dataMap['your_attribute_identifier']->attribute( 'content')->attribute( 'output' );
$xhtml = $output->outputText();

Cheers,
Hakim

André R.

Thursday 04 June 2009 6:02:24 am

Hakim: what class is $output? ( call "var_dump($output);" for instance)

$ouput->attribute( 'output_text' ); should have worked, as it uses outputText() in eZXMLOutputHandler, but if you have another output handler for some reason, then it might not work.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Hakim Bouras

Friday 05 June 2009 4:50:45 am

I retried the code provided by Damien, and in fact it is working fine. I probably missed something the first time I tried.

Thanks again for your help, and sorry for the burden,
Hakim

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 03:22:09
Script start
Timing: Jan 31 2025 03:22:09
Module start 'layout'
Timing: Jan 31 2025 03:22:09
Module start 'content'
Timing: Jan 31 2025 03:22:09
Module end 'content'
Timing: Jan 31 2025 03:22:09
Script end

Main resources:

Total runtime0.0299 sec
Peak memory usage4,096.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0042 588.2656151.2266
Module start 'layout' 0.00420.0034 739.4922220.7188
Module start 'content' 0.00760.0204 960.21091,001.9609
Module end 'content' 0.02800.0018 1,962.171937.9922
Script end 0.0298  2,000.1641 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00279.0403140.0002
Check MTime0.00123.8589140.0001
Mysql Total
Database connection0.00072.304810.0007
Mysqli_queries0.00237.547730.0008
Looping result0.00000.029510.0000
Template Total0.00134.410.0013
Template load0.00103.336610.0010
Template processing0.00031.011810.0003
Override
Cache load0.00072.324810.0007
General
dbfile0.00155.097680.0002
String conversion0.00000.012840.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