Forums / Developer / How to make xml data in module?

How to make xml data in module?

Author Message

Jerry Jalava

Tuesday 18 November 2003 8:38:03 pm

Hi again,

I'm building an import script from AM to eZ and I would like to know how can I insert text data to xml datatype field inside own module?
And also would like to know how to do the same thing with ezauthor datatype.

I've founded how to insert data to normal textfield datatype:
$contentObjectAttributes[0]->setAttribute( 'data_text', $title );
$contentObjectAttributes[0]->store();

But know I could use some help with the xml data...

Thanks again,
Jerry

Paul Forsyth

Wednesday 19 November 2003 2:07:50 am

Its a little more complicated because the string has to be valid xml for the field to work properly.

Heres a code snippet i use to add some a string and some comments. Hope it makes sense :)

paul

-----

$contentObjectAttribute =& $contentObjectAttributes[$key];
$contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();

if ($contentClassAttribute->attribute("name") == "My attribute")
{
$xml = new eZXML();

// Retain the current content of the attribute.
$presentContent=$contentObjectAttribute->attribute("data_text");

// Prepare the original xml for new information.
if ($presentContent != "")
{
// Turn this content into a dom tree so we can add to it.
$originalDomTree =& $xml->domTree( $presentContent );

$originalRoot =& $originalDomTree->root();

$commentSeperator =& $originalDomTree->createElementNode( "paragraph" );
$emphasizeDomNode =& $originalDomTree->createElementNode( "emphasize" );
$emphasizeDomNode->appendChild( $originalDomTree->createTextNode( "------- Additional Comment -----------" ) );

$commentSeperator->appendChild($emphasizeDomNode);

$originalRoot->appendChild( $commentSeperator );
}

// Now re-set the attribute with our new comments. Comments
// contains new xml
$contentObjectAttribute->setAttribute("data_text", $comments);

// Turn the new comments into xml by invoking the ez parsing routines.
$xmlText = new eZXMLText( eZXMLTextType::rawXMLText( $contentObjectAttribute ), $contentObjectAttribute );
$input =& $xmlText->attribute( 'input' );
$isValid = $input->validateInput( $http, "ContentObjectAttribute", $contentObjectAttribute );

// Create a new tree with our newly formed xml.
$newDomTree =& $xml->domTree( $contentObjectAttribute->attribute("data_text") );
$newRoot =& $newDomTree->root();

// First determine whether we should store the new or original xml.
// Add the new children to the original xml.
if ($presentContent != "")
{
if ($newRoot->hasChildren())
{
$rootChildren =& $newRoot->children();
foreach($rootChildren as $child)
{
$originalRoot->appendChild( $child );
}
}

$contentObjectAttribute->setAttribute("data_text", $originalDomTree->toString());
}
else
{
$contentObjectAttribute->setAttribute("data_text", $newDomTree->toString());
}

Paul Forsyth

Wednesday 19 November 2003 2:09:20 am

ack. wish i could use literal to hide the code from the smileys.

jerry, feel free to email me at paul [at] visionwt [dot] com and ill send you the code is use in a better form.

paul

Jerry Jalava

Wednesday 19 November 2003 6:06:24 am

Hi Paul,

Thank you alot... I haven't tested the script yet, but believe it works like a charm.

I'll try it first from here and will email if it doesn't wan't to work... ;)

Once again thank you alot.

Regards,
Jerry

eZ debug

Timing: Jan 30 2025 21:20:54
Script start
Timing: Jan 30 2025 21:20:54
Module start 'content'
Timing: Jan 30 2025 21:20:54
Module end 'content'
Timing: Jan 30 2025 21:20:55
Script end

Main resources:

Total runtime0.2301 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0069 587.9297370.2969
Module start 'content' 0.00690.0132 958.22661,005.4063
Module end 'content' 0.02010.2100 1,963.63283,894.4375
Script end 0.2301  5,858.0703 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00431.8496200.0002
Check MTime0.00130.5459200.0001
Mysql Total
Database connection0.00080.336710.0008
Mysqli_queries0.139660.65041410.0010
Looping result0.00120.52581390.0000
Template Total0.209691.110.2096
Template load0.00080.353710.0008
Template processing0.208890.746610.2088
Override
Cache load0.00060.254710.0006
Sytem overhead
Fetch class attribute can translate value0.00180.784410.0018
XML
Image XML parsing0.00020.107910.0002
General
dbfile0.00572.4963200.0003
String conversion0.00000.002630.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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs