This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Learn » eZ Publish » Creating eZ Publish Objects in PHP

Creating eZ Publish Objects in PHP

Friday 04 June 2010 5:09:02 pm

  • Currently 5 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Step 3 - Adding the Content (continued)

Importing XML Fields

XML fields are more difficult due to the structure they are stored in within the database. You need to make sure you wrap your text within the extra xml layers to add it successfully. The folder object also has a description field we omitted in the first example so let’s look at the code needed to add content to that. eZ Publish has some built in methods for converting html to the correct format so we can just use these.

This code should be used in the step “Preparing the object attributes” found above:

Code :

// setting attribute values// updating the structure for the valid XML
$XMLContent =<h1>Big Title</h1><h2>Littler Title</h2><p>page content here. Go to <a href=""></a>?</p>;//my example content
//creating and setting up the parser
$parser = new eZSimplifiedXMLInputParser( );
$parser->setParseLineBreaks( true );
//parsing the content
$document = $parser->process( $XMLContent );
//adding the content to an object
$attributesData ['description'] = eZXMLTextType::domString( $document );$contentObject = eZContentFunctions::createAndPublishObject( $params );

Below is an example of this XML content before and after it is passed into the XML parser. As you can see a lot of extra information is added to the HTML which would be difficult to add manually.

eZXMLText, before and after

Whenever this is displayed to the user, the formatting will be converted back to HTML. If we add the XML code to our previous example, the result is as follows:

Visual result of XML import

As you can see, the formatting has been reverted back to HTML. Please note that not all HTML tags can be imported into XML (although custom tags can be added when necessary), for a complete list of the tags available by default, please see the documentation.



Printer Friendly version of the full article on one page with plain styles


Proudly Developed with from