WILT #1 - Tricks with <display>

Posted 05/04/2010 - 19:51 by nzblue_fish

5
Your rating: None Average: 5 (2 votes)

Hi mashers,

My good friend Jess and I talked a few weeks ago about posting useful tips that I've learnt on my journey through mashups with Presto. Jess, I think is working on bringing something more structure to the MDC, but since I have the memory of a goldfish, I'm starting to worry that I might forget some of the things I've learnt along the way. So, while Jess works her magic in the background, I'm going to blog some days on "What I've Learnt Today (WILT)" so I don't lose them to a "memory overwrite" and can share them with everyone else.

I make use of <display> a lot during my mashup development of custom emml with Presto Studio. Sometimes I use the debug facility and set breakpoints, but more often than not, I use <display> to show what's happening during the mashup execution and to display the values of nodes so I know I've got the data I thought I had. Here's a couple of things I've learnt that make my life easier.

I hope these help others learning to mashup ... and more to come soon on my current progress with my 35 Mashups Challenge.

Cheers, Innes

Pretty Up Your <display> Output

One trick I use often now, because a lot of  <display> activity can get a bit hard to read in the Studio console window, is to add carriage returns and linefeeds to separate key display statements. This is easy by adding encoded CR's and LF's as part of the message attribute of  <display>. So <display message="&#10;&#13;clinicgrp=" variable="clinicgrp" /> will very nicely display my message clinicgrp= and the variable value on a line all of its own in the console window.

You can even add tabs by adding in &#09; if you want.

Usually, I delete or comment out my <display>'s once things go in to production, but I also build emml scripts that exercise macros I've written with standard sets of tests. When I run these, they output using <display> the results of those tests. Having these appear in a nice format in the console window helps to highlight tests that have failed.

You can leave some <display>'s in your production emml if you want. The output (at least with Tomcat) appears in the console window when the mashup is executed. Not bad for diagnostic messages.

Make That text() Work

When I started learning to write XPath expressions in my emml, I relied heavily on <display> and the expr attribute to show me what I was actually extracting from a node or document, and since I often wanted to see the content of the text node I used the "text()" reference in my XPath expression.

It took me simply ages and much head-banging to discover that when you use the "text()" reference in a XPath expression with <display> it doesn't quite work the way you'd expect it to.

Let's say we have a document fragment in some variable ($myVariable):

<somenode>

<field1>my text</field1>

</somenode>

and I want to display the text node for field1 (i.e "my text") then I would have expected that the following to work:

<display message="field1 content=" expr="$myVariable/*:somenode/*:field1/text()" />

but it doesn't, you'll get field1 content= in your console window.

However (and this I stumbled across by trial and error), if you wrap your "text()" expression in a "string()" you'll get exactly what you expected, like so:

<display message="field1 content=" expr="$myVariable/*:somenode/*:field1/string(text())" />

Here's a small emml script that demonstrates this fully and the output it will generate:

<mashup xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.jackbe.com/2008-03-01/EMMLSchema/ ../src/schemas/EMMLSpec.xsd"
      xmlns="http://www.jackbe.com/2008-03-01/EMMLSchema"
      xmlns:macro="http://www.jackbe.com/2008-03-01/EMMLMacro"
      name = "test22">
      
      <operation name="runTest22">
      
          <variables>
              <variable name="testDocument" type="document">
                  <root>
                      <somenode>
                          <field1>my text</field1>
                      </somenode>
                  </root>
              </variable>
          </variables>
         
          <display message="&#10;&#13;********** WILT #1 Code Example ************" />
         
          <display message="&#10;&#13;Test One - Text() Does Not Work" />
          <display message="&#10;&#09;field1=" expr="$testDocument/*:root/*:somenode/*:field1/text()" />
         
          <display message="&#10;&#13;Test Two - Text() Does Work" />
          <display message="&#10;&#09;field1=" expr="$testDocument/*:root/*:somenode/*:field1/string(text())" />
         
          <display message="&#10;&#13;********** End of WILT #1 Code Example ************" />
         
      </operation>
 
 </mashup>
Executing the script... 

********** WILT #1 Code Example ************   

Test One - Text() Does Not Work   
    field1=   

Test Two - Text() Does Work   
    field1=    my text


********** End of WILT #1 Code Example ************
Comment viewing options
Select your preferred way to display the comments and click "Save settings" to activate your changes.
Hey Innes, Thanks for

Hey Innes,

Thanks for sharing! Keep them coming. Looking forward to your next WILT so I can learn something more too :-)

Mash On!
- deepak alur | vp product + engineering at jackbe  | follow me

Posted by Deepak Alur on Tue, 05/04/2010 - 23:50
Hi Sara, thanks for that. I

Hi Sara,

thanks for that.

I posted on the problem with text() a while back (see http://www.jackbe.com/enterprise-mashup/forum/accessing-text-nodes-display ) and wondered if it was a bug  then. Great if it gets fixed in an upcoming release. Just thought others starting out might run in to the same issue I did and could help them avoid the "Hmmmm! what did I do wrong" when what they did should have worked.

Cheers, Innes

 

Posted by nzblue_fish on Tue, 05/04/2010 - 22:10
Nice tips. Although I think

Nice tips. Although I think the tip on using string() around text() is only needed because you have discovered a bug. But still a good catch (and I will investigate the bug question :)

<!--Session data-->

 

Sara, technical writer/jackbe

 

Posted by smitchell on Tue, 05/04/2010 - 20:02
 Innes / Sara, text() display

 Innes / Sara,

text() display issue is indeed a bug. It will be fixed in the upcoming release. 

raj.  chief masher @ jackbe

Posted by raj on Wed, 05/05/2010 - 13:42
Comment viewing options
Select your preferred way to display the comments and click "Save settings" to activate your changes.