Urgent: How to generate XML to insert in a attribute?

Author Message

christian bencivenni

Thursday 24 August 2006 10:56:00 pm

Hi to all.
I have the problem to create (with APIs) a new predefined object with some attributes.
One of them is an ezxmltext datatype attribute. I create it with the ezcontentobject_attribute::create( ); method but I also need to fill it with information.
The attribute "data_text" must contain the XML schema.
I need to generate a simple void XML block and add to it a string of plain text as a content.
How can I do it with the Ez API or other classes methods?
I read all the code source for XML datatype but in the handlers nothing seems to do it.
Thank you for your help.

Xtian

Łukasz Serwatka

Thursday 24 August 2006 11:16:07 pm

Hi,

For output see:
See example in this topic:
http://ez.no/community/forum/install_configuration/ez_xml_to_html/re_ez_xml_to_html__1

for input data use

include_once ('lib/ezutils/classes/ezfunctionhandler.php');

$node = eZFunctionHandler::execute( 'content','node', array( 'node_id' => 2) );
$object =& $node->object();

foreach( $object->contentObjectAttributes() as $contentObjectAttribute )
{
    include_once( 'kernel/classes/datatypes/ezxmltext/handlers/input/ezsimplifiedxmlinput.php' );
    include_once( 'kernel/classes/datatypes/ezxmltext/handlers/input/ezsimplifiedxmlinputparser.php' );
    include_once( 'kernel/classes/datatypes/ezxmltext/ezxmltexttype.php' );
    
    $XMLContent = "<section><paragraph>text</paragraph></section>";

    $parser = new eZSimplifiedXMLInputParser( $object->attribute( 'id' ) );
    $parser->setParseLineBreaks( true );

    $document = $parser->process( $XMLContent );

    $xmlString = eZXMLTextType::domString( $document );

    if ( $contentObjectAttribute->attribute( 'data_type_string' ) == 'ezxmltext' )
    {
        $contentObjectAttribute->setAttribute( 'data_text', $xmlString );
        $contentObjectAttribute->store();
    }
}

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

christian bencivenni

Friday 25 August 2006 12:18:51 am

Thank you a lot for your help.
A couple of questions:
1) $node = eZFunctionHandler::execute( 'content','node', array( 'node_id' => 2)
Should I put "my_object_node_id" node id here? Is correct?

2)$XMLContent = "<section><paragraph>text</paragraph></section>";
Should I put "my_text_string" content instead of text here? Is correct?

thanks again.

Łukasz Serwatka

Friday 25 August 2006 6:52:33 am

Ad.1)

Yes, replace with your node_id

Ad.2)

Yes.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

christian bencivenni

Friday 25 August 2006 10:12:49 pm

It works!
Thank you a lot.

Łukasz Serwatka

Saturday 26 August 2006 2:30:28 am

You are welcome, christian ;)

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

christian bencivenni

Monday 28 August 2006 10:40:44 pm

So...
I ask you another thing: What exactly is a Dom document (or a DOMstring in the text above)?

Łukasz Serwatka

Monday 28 August 2006 10:54:46 pm

Content in ezxmltext datatype is stored as XML structure, base on parser output eZXMLTextType::domString() creates XML structure which you can store in attribute.

<?xml version="1.0" encoding="UTF-8"?>
<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
         xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"
         xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">
  <paragraph>some text
    <strong>this is bold text</strong> some text
    <emphasize>some text</emphasize>
  </paragraph>
</section>

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Sébastien Antoniotti

Saturday 10 February 2007 3:37:53 am

Hi,

I'm using your solutio to insert text like this into an ezxmltext attribute :

Da sbarracà i palazzi   <br />
                   MI min / LA min<br />
E da spenticà limperi <br />
                    SI 7 / MI min<br />
Venutu da i to stazzi <br />
                       FA / MI min<br />
Cù i to cavalli fieri   <br />
                       SI 7 / MI min<br />
<br />
Attila si scalatu<br />
Cù u ferr è cù u focu<br />
Vecu e greghje infuriate<br />
Ad apparinà u locu<br />

The problem is that special characters like à,ù, etc. make fail the insertion. Replacing them by &agrave; is ok but the accent is not interpreted when rendering...

Maybe a problem with the encoding of the xml text generated by the parser no ?

eZ Publish Freelance
web : http://www.webaxis.fr

Xavier Dutoit

Wednesday 14 February 2007 5:19:21 am

Salut,

You have to convert you text to the charset you use to make it work (I think there is an option to have several charsets, but I'd rather don't use it).

Say your site is in utf8 and your external xhtml in latin1 you have to utf8 encodes it.

Welcome to the jungle...

X+

http://www.sydesy.com

Sébastien Antoniotti

Wednesday 14 February 2007 8:00:46 am

Hi Xavier,

After a lot of mistake I finally success with my script who import a joomla structure (section>category>content_item) to the ezpublish tree.

So for my charset problem, solution I found was to set the mysql transaction in utf-8 by a

mysql_query("SET CHARACTER SET utf8");

before making the query, and use this (found into ezpedia.org) :

        // $introtext is a joomla content text (jos_content table)
	$XMLContent = $introtext;
	//$cli->output($introtext);
	$parser = new eZSimplifiedXMLInputParser( $object->attribute( 'id' ) );
	$parser->setParseLineBreaks( false );
	 
	$document = $parser->process( $XMLContent );
	 
	// Create XML structure
	$xmlString = eZXMLTextType::domString( $document );

Thanks for your help ;-)

eZ Publish Freelance
web : http://www.webaxis.fr

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 19 2025 03:26:18
Script start
Timing: Jan 19 2025 03:26:18
Module start 'layout'
Timing: Jan 19 2025 03:26:18
Module start 'content'
Timing: Jan 19 2025 03:26:20
Module end 'content'
Timing: Jan 19 2025 03:26:20
Script end

Main resources:

Total runtime1.2251 sec
Peak memory usage4,096.0000 KB
Database Queries85

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0052 589.3047152.6406
Module start 'layout' 0.00520.0022 741.945339.4766
Module start 'content' 0.00741.2161 781.4219726.5078
Module end 'content' 1.22360.0015 1,507.929724.1250
Script end 1.2251  1,532.0547 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.2845160.0002
Check MTime0.00150.1222160.0001
Mysql Total
Database connection0.00120.096110.0012
Mysqli_queries1.137592.8459850.0134
Looping result0.00070.0574830.0000
Template Total1.188897.020.5944
Template load0.00290.239220.0015
Template processing1.185996.795820.5929
Template load and register function0.00020.015810.0002
states
state_id_array0.00160.130510.0016
state_identifier_array0.00120.099520.0006
Override
Cache load0.00260.2162700.0000
Sytem overhead
Fetch class attribute can translate value0.00060.044940.0001
Fetch class attribute name0.00140.1154140.0001
XML
Image XML parsing0.00390.321440.0010
class_abstraction
Instantiating content class attribute0.00000.0030180.0000
General
dbfile0.00360.2958300.0001
String conversion0.00000.000540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
11content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
16content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 47
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs