eZ Community » Forums » Extensions » Converting ezstring to ezxml with...
expandshrink

Converting ezstring to ezxml with ezchangeclass extension

Converting ezstring to ezxml with ezchangeclass extension

Tuesday 04 September 2007 4:58:43 pm - 2 replies

I love the Modzelewski's extension "Object content class change" ( http://ez.no/community/contribs/applications/object_content_class_change ) but I need to convert a class with string attributes to another with xml blocks.
This extension provide the mechanism for converting attribute types not supported by external script (PHP code).
Anyone know what are the right eZ methods/functions to use for such conversion?

Thanks in advance...

Modified on Thursday 06 September 2007 9:30:08 am by Mauro Innocenti

Wednesday 05 September 2007 3:17:43 pm

I think this is the right way to follow:
http://ez.no/community/forum/deve...enerate_xml_to_insert_in_a_attribute

Modified on Wednesday 05 September 2007 3:17:53 pm by Mauro Innocenti

Friday 14 September 2007 10:30:13 am

You can try to build a module implementing this a function like this :

    function build_xml_string($string_to_convert) {    
	 include_once( "lib/ezxml/classes/ezxml.php" );
        $doc = new eZDOMDocument( "" );

        // create the root xml node
        $root = $doc->createElementNode( "section" );			
        $doc->setRoot( $root );
        $root->appendAttribute( $doc->createAttributeNode( "xmlns:image", "http://ez.no/namespaces/ezpublish3/image/" ) );
        $root->appendAttribute( $doc->createAttributeNode( "xmlns:xhtml", "http://ez.no/namespaces/ezpublish3/xhtml/" ) );
        
        $content_paragraphs = explode ("\r\n\r\n", $string_to_convert);
        foreach ($content_paragraphs as $content_paragraph) {
	        unset( $paragraph_node );
			$paragraph_node =& $doc->createElementNode( "paragraph" );
			$content_lines = explode ("\r\n", $content_paragraph);
  			foreach ($content_lines as $content_line) {
				unset( $line_node );
				unset( $text_node );
				$line_node =& $doc->createElementNode( "line" );
				$paragraph_node->appendChild( $line_node );						
				$text_node =& $doc->createTextNode( $content_line );
				$line_node->appendChild($text_node);
			}	
			$root->appendChild( $paragraph_node );
        }
        
		$xml_string = $doc->toString();
        return $xml_string;
    }

After what you just have to retrieve the content of your linetext attributes, convert it using this function, and assign it to the data_text field of your XMLBloc attributes like this

    $xmlbloc_contentobjectattribute->setAttribute("data_text", $xml_string);

But it's a "dirty" way to do if you think about forward compatibilty, because the XML model of XMLBloc attributes can be changed in the future.
A better way to do it would be to refer to /kernel/classes/datatypes/ezxmltext/ezxmlschema.php or something like this.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from