Forums / Developer / Urgent: How to generate XML to insert in a attribute?

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

eZ debug

Timing: Jan 19 2025 00:31:00
Script start
Timing: Jan 19 2025 00:31:00
Module start 'content'
Timing: Jan 19 2025 00:31:01
Module end 'content'
Timing: Jan 19 2025 00:31:02
Script end

Main resources:

Total runtime1.0508 sec
Peak memory usage4,096.0000 KB
Database Queries222

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0137 587.8594180.8125
Module start 'content' 0.01370.9216 768.6719731.6016
Module end 'content' 0.93530.1154 1,500.2734348.4297
Script end 1.0507  1,848.7031 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00500.4727210.0002
Check MTime0.00150.1454210.0001
Mysql Total
Database connection0.00150.145910.0015
Mysqli_queries0.937089.16842220.0042
Looping result0.00230.21912200.0000
Template Total0.993694.620.4968
Template load0.00210.204520.0011
Template processing0.991594.354520.4957
Template load and register function0.00020.021110.0002
states
state_id_array0.00150.144510.0015
state_identifier_array0.00200.186320.0010
Override
Cache load0.00200.1921700.0000
Sytem overhead
Fetch class attribute can translate value0.00160.147650.0003
Fetch class attribute name0.00120.1178140.0001
XML
Image XML parsing0.00200.192150.0004
class_abstraction
Instantiating content class attribute0.00000.0034180.0000
General
dbfile0.00310.2980410.0001
String conversion0.00000.000730.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
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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 47
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs