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.