Forums / Developer / How to test an xml text field is empty

How to test an xml text field is empty

Author Message

Paul Forsyth

Saturday 03 May 2003 5:18:09 am

I have some html i wish to display when an xml text field attribute has some data and hide when it does not. There is a graphic header above the text which also hides when the text is empty.

I've put a section around this code to show when the field is not empty but i've found it hard to actually test that the text doesn't contain anything. Because it is an xml text field it by default contains xml. I have had to resort to the following code to allow this test to work. But is there a better way? Perhaps the object should have another attribute to show if it contains anything?

{section name=Hide show=ne($content_version.data_map.my_xmltextfield.data_text,'<?xml version="1.0" encoding="UTF-8"?>
<section />')}

thanks

Paul

Tony Wood

Saturday 03 May 2003 6:04:26 am

On my system the code needs to be

{section name=Hide show=ne($content_version.data_map.my_xmltextfield.data_text,'<?xml version="1.0" encoding=""?>
<section />')}

As the encoding does not show up for me.

Very strange.

Tony Wood : twitter.com/tonywood
Vision with Technology
Experts in eZ Publish consulting & development

Power to the Editor!

Free eZ Training : http://www.VisionWT.com/training
eZ Future Podcast : http://www.VisionWT.com/eZ-Future

Paul Forsyth

Friday 09 May 2003 3:27:46 am

Any comment on this?

Since the xml returned isn't formatted correctly it may be worth filing a bug on that alone...

Paul

Stuart Fenton

Monday 12 May 2003 4:34:37 am

I have tried lots of ways to test if an XML field is empty with no solution.

I have read other article within the EZ site about testing for empty fields using several tests but they don't work for XML fields.

How can I test for an empty field.

I have modified the article object to include multiple columns of information but want to check if the are empty or not and alter the html code presented to change the design into 1,2 or 3 column format.

In order to do this I must test for an empty XML field and change the design accordingly.

How is this achieved?

None of the articles on testing seem to work for XML fields.

Any ideas?

-- Stuart

stuart@grandmore.com
http://www.grandmore.com

Tony Wood

Thursday 15 May 2003 1:38:38 am

Any ideas eZ?

Tony Wood : twitter.com/tonywood
Vision with Technology
Experts in eZ Publish consulting & development

Power to the Editor!

Free eZ Training : http://www.VisionWT.com/training
eZ Future Podcast : http://www.VisionWT.com/eZ-Future

Bård Farstad

Wednesday 28 May 2003 2:44:29 am

There is actually no good function for this. We should implement an is_empty attribute to check this.

I will start coding right away.

--bård

Documentation: http://ez.no/doc

Bård Farstad

Wednesday 28 May 2003 4:24:32 am

I've just commited a function which does this on ezxmltext datatypes. You can now do:

{section show=$attribute.content.is_empty}
is empty
{section-else}
is not empty
{/section}

Committed revision 2624 in svn.

--bård

Documentation: http://ez.no/doc

Tony Wood

Wednesday 28 May 2003 4:34:42 am

Thanks Bård,

Will this check make it into 3.0 stable as the project this is used for is on latest stable release.

tia

tony

Tony Wood : twitter.com/tonywood
Vision with Technology
Experts in eZ Publish consulting & development

Power to the Editor!

Free eZ Training : http://www.VisionWT.com/training
eZ Future Podcast : http://www.VisionWT.com/eZ-Future

Bård Farstad

Wednesday 28 May 2003 5:06:58 am

Tony, this will not be merged into the 3.0 stable. It will be part of the 3.1 stable which will be relesed in 4 weeks.

--bård

Documentation: http://ez.no/doc

Barney Gumble

Wednesday 21 January 2004 8:17:39 am

I'm using 3.2.4 with the Online Editor, and am still having this problem. It seems that an XML field can never return to the 'empty' state, even after clearing all the text from it. This makes it impossible to use a function such as is_empty.

Looking at the above potential solutions, how can I see the actual XML which the field is left with, i.e. how can I get <?xml version="1.0" encoding="UTF-8"?> or similar to show up? If I knew this then I could check for that string instead of looking for it to be empty.

Paul Forsyth

Wednesday 21 January 2004 8:24:42 am

Do you have a database viewer such as webmin, myphpadmin, or mysql control center? With any of these you will be able to look at the content object attribute and see the xml for yourself.

paul

Marco Zinn

Wednesday 21 January 2004 12:40:08 pm

Hi Barney,
if you think, the problem is the OE, why don't you turn it off temporarly, delete the contents of the field and save the object?
I'm not using OE and tests for "is_empty" were sucessfull.

Marco
http://www.hyperroad-design.com

Barney Gumble

Wednesday 21 January 2004 4:39:37 pm

Paul - Thanks, I was going to try and hook myphpadmin up soon anyway so I might as well go ahead.

Marco - Yes that does in fact work, but I can't rely on the editors to remember to do that each time unfortunately. Fingers crossed for option 1!

Thanks guys as always.

Harry Oosterveen

Thursday 25 March 2004 2:39:37 am

What works well for me, is to add two PHP functions to convert XML text fields into plain trimmed text. Add the following lines in template.ini:

[PHP]
PHPOperatorList[striptags]=strip_tags
PHPOperatorList[wstrim]=trim

(The eZ publish trim function appears not to trim linebreaks)

Now you can test in a template:
{section show=ne($content_version.data_map.my_xmltextfield.data_text|striptags|wstrim)}

eZ debug

Timing: Jan 18 2025 14:52:58
Script start
Timing: Jan 18 2025 14:52:58
Module start 'content'
Timing: Jan 18 2025 14:53:00
Module end 'content'
Timing: Jan 18 2025 14:53:00
Script end

Main resources:

Total runtime1.4366 sec
Peak memory usage4,096.0000 KB
Database Queries237

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0064 588.9453180.8281
Module start 'content' 0.00641.2543 769.7734872.9141
Module end 'content' 1.26070.1758 1,642.6875357.3359
Script end 1.4365  2,000.0234 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00410.2864210.0002
Check MTime0.00150.1057210.0001
Mysql Total
Database connection0.00150.102010.0015
Mysqli_queries1.325092.23542370.0056
Looping result0.00270.18642350.0000
Template Total1.407598.020.7038
Template load0.00210.148820.0011
Template processing1.405497.829220.7027
Template load and register function0.00020.012710.0002
states
state_id_array0.00070.049010.0007
state_identifier_array0.00090.061620.0004
Override
Cache load0.00190.1340820.0000
Sytem overhead
Fetch class attribute can translate value0.00150.106280.0002
Fetch class attribute name0.00120.0813190.0001
XML
Image XML parsing0.00650.454280.0008
class_abstraction
Instantiating content class attribute0.00010.0075230.0000
General
dbfile0.00750.5200510.0001
String conversion0.00000.000430.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
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
14content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
19content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
9content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 50
 Number of unique templates used: 6

Time used to render debug report: 0.0003 secs