Forums / Developer / import ezxml datatype in PHP CLI script

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

import ezxml datatype in PHP CLI script

Author Message

Fabio Carissimi

Tuesday 11 July 2006 1:58:47 am

Hello,

I have an error when I use the fonction setEZXMLAttribute() which is defined in rssimport.php (in cronjobs) to import
xmlblock datatype in an object within a php CLI script.
here the function

function setEZXMLAttribute( &$attribute, &$attributeValue, $link = false )
{
    include_once( "kernel/classes/datatypes/ezxmltext/handlers/input/ezsimplifiedxmlinput.php" );
    $inputData = "<?xml version=\"1.0\"?>";
    $inputData .= "<section>";
    $inputData .= "<paragraph>";
    $inputData .= $attributeValue;
    $inputData .= "</paragraph>";
    $inputData .= "</section>";       
    $dumpdata = "";    

    $simplifiedXMLInput = new eZSimplifiedXMLInput( $dumpdata, null, null );
    $inputData = $simplifiedXMLInput->convertInput( &$inputData );
    $domString = eZXMLTextType::domString( $inputData[0]);
	
    $domString = str_replace( "<paragraph> </paragraph>", "", $domString );
    $domString = str_replace ( "<paragraph />" , "", $domString );
    $domString = str_replace ( "<line />" , "", $domString );
    $domString = str_replace ( "<paragraph></paragraph>" , "", $domString );
    $domString = str_replace( "<paragraph>&nbsp;</paragraph>", "", $domString );
    $domString = str_replace( "<paragraph></paragraph>", "", $domString );
    $domString = preg_replace( "#[\n]+#", "", $domString );
    $domString = preg_replace( "#&lt;/line&gt;#", "\n", $domString );
    $domString = preg_replace( "#&lt;paragraph&gt;#", "\n\n", $domString );

    $xml = new eZXML();
    $tmpDom =& $xml->domTree( $domString, array( 'CharsetConversion' => false ) );
    $description = eZXMLTextType::domString( $tmpDom );

    $attribute->setAttribute( 'data_text', $description );
    $attribute->store();
}

the error message is

Fatal error: Call to a member function on a non-object in /var/www/Exponential/kernel/classes/datatypes/ezxmltext/ezxmltexttype.php on line 340

the line 340 of ezxmltexttype.php is $domString = $domDocument->toString( $charset ); in the domString() function
so it refers to $domString = eZXMLTextType::domString( $inputData[0]); and it happens because $inputData[0] is empty.
it seems that in these 2 lines

 $simplifiedXMLInput = new eZSimplifiedXMLInput( $dumpdata, null, null );
    $inputData = $simplifiedXMLInput->convertInput( &$inputData );

the inputData has been lost (I have verified it with debug outputs) and I don't know why.
In a first time, I thought that it was an encoding problem and I used utf8_encode() to give
utf8 data to the function but the problem remains. I also tried to insert data without using dom and xml treatment,
only putting the data in the xml body (<?xml version=\"1.0\"?><section><paragraph>$attributeValue</paragraph></section>)
and set the attribute ($attribute->setAttribute( 'data_text', $description );) and it works,
but I believe there are reasons to do this xml treatment.
So, somebody knows where is the problem ?

Thanks for help

Kirill Subbotin

Wednesday 12 July 2006 12:29:52 am

Which eZp version are you using?

Fabio Carissimi

Wednesday 12 July 2006 2:13:22 am

Hello,

This is Exponential 3.8.0 with php 4.4.2, MySql 4.1.18, Apache 2.0.55 (on a Mandriva Linux Limited Edition 2005).

Thanks for help

Fabio Carissimi

Wednesday 12 July 2006 2:48:34 am

Your question helps me to find the problem,
I have upgraded to Exponential 3.8.1 and it works fine

it was a bug and it has been fixed: see http://ez.no/bugs/view/8343

Thanks for your help :-)

Kirill Subbotin

Wednesday 12 July 2006 3:46:01 am

I verified that fix, and found that it's not ok too. See my report
http://ez.no/community/bugs/rss_import_to_xml_text_block_is_broken

Here is the correct function for 3.8 :

function setEZXMLAttribute( &$attribute, &$attributeValue, $link = false )
{
    include_once( 'kernel/classes/datatypes/ezxmltext/handlers/input/ezsimplifiedxmlinputparser.php' );
    $contentObjectID = $attribute->attribute( "contentobject_id" );
    $parser = new eZSimplifiedXMLInputParser( $contentObjectID, false, 0 );

    $attributeValue = str_replace( "\r", '', $attributeValue );
    $attributeValue = str_replace( "\n", '', $attributeValue );
    $attributeValue = str_replace( "\t", ' ', $attributeValue );

    $document = $parser->process( $attributeValue );
    if ( !is_object( $document ) )
    {
        $cli =& eZCLI::instance();
        $cli->output( 'Error in xml parsing' );
        return;
    }
    $domString = eZXMLTextType::domString( $document );

    $attribute->setAttribute( 'data_text', $domString );
    $attribute->store();
}

Fabio Carissimi

Wednesday 12 July 2006 9:06:24 am

ok
I am using this one now and everything is ok

Thanks