Integrate Software AG Products Using Digital Event Services : MashZone NextGen Help : Appendix : Legacy Presto components : Mashables and Mashups : Mashups in EMML : Advanced Mashup Techniques : Wrapping Results or Variables in CDATA Sections
Wrapping Results or Variables in CDATA Sections
In some cases, XML content uses CDATA sections to treat element content that may contain markup as though it is text. This is most commonly used to avoid having to escape HTML markup that is inside XML elements to keep the markup intact for later processing. However, it can be applied to any element content that may have HTML or XML markup which you need to escape as an entire block.
Common examples are web feeds using RSS or Atom formats where article titles or descriptions contain HTML. For example:
<rss>
<channel>
...
<item>
<title><![CDATA[The <b>article</b> title with <span
>markup</span>]]></title>
...
</item>
...
</rss>
You can wrap the contents of specific elements in CDATA sections in the result of a mashup or in variables. Use the output-cdata-section-elements attribute on either the <output> or <variable> declarations.
The value of output-cdata-section-elements is the name of one or more elements whose content should be wrapped in a CDATA section. For example:
<variable name="postBody" type="document"
output-cdata-section-elements ="title description" />
If the elements in question have namespaces, you must add the namespace in the form {namespace-URI} before the element name. For example:
<output name="result" type="document"
output-cdata-section-elements =
"{http://www.opengis.net/kml/2.2}text
{http://www.opengis.net/kml/2.2}bgColor" />
For common examples of wrapping results in CDATA sections, see:
*CDATA Sections in <output>
*CDATA Sections in <variable> Used as Input to Mashables/Mashups
*CDATA Sections in <variable> When Casting Strings to Documents
CDATA Sections in <output>
With an input document in the following form, the CDATA section in the <text> element is stripped by the parser, but the HTML markup remains:
<kml xmlns="http://www.opengis.net/kml/2.2">
<document>
<Style id="medSporeCountBalloon">
<BalloonStyle>
<bgColor>#EBFFEB</bgColor>
<text><![CDATA[<h1>Some HTML content</h1>]]></text>
</BalloonStyle>
</Style>
</document>
</kml>
With an <output> declaration for the mashup in the form:
<output name="result" type="document"
output-cdata-section-elements =
"{http://www.opengis.net/kml/2.2}text
{http://www.opengis.net/kml/2.2}bgColor" />
The final result of the mashup wraps the content of both the <text> and the <bgColor> elements in CDATA markers:
<kml xmlns="http://www.opengis.net/kml/2.2">
<document>
<Style id="medSporeCountBalloon">
<BalloonStyle>
<bgColor><![CDATA[#EBFFEB]]></bgColor>
<text><![CDATA[<h1>Some HTML content</h1>]]></text>
</BalloonStyle>
</Style>
</document>
</kml>
CDATA Sections in <variable> Used as Input to Mashables/Mashups
Another common scenario occurs when a mashable or other information source expects an input variable with XML content that contains CDATA sections.
<mashup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openmashup.org/schemas/v1.0/EMML/../schemas/EMMLSpec.xsd"
xmlns="http://www.openmashup.org/schemas/v1.0/EMML"
name="queryPost">

<output name="result" type="document"/>
<!-- comma separated list of terms to search for -->
<input name="terms" type="string"/>
<variable name="words" type="document" />

<assign fromexpr="tokenize($terms,',')" outputvariable="words" />
<constructor outputvariable="postBody"><query/></constructor>

<foreach items="$words" variable="word">
<variable name="searchList" type="document"
cdata-output-section-elements="term"/>
<appendresult outputvariable="$searchList">
<term>{$word}</term>
</appendresult>
<appendresult outputvariable="$postBody">
{$searchList}
</appendresult>
</foreach>
...
<directinvoke endpoint="$queryService" method="POST" header="$contentType"
requestBody="$postBody"/>
</mashup>
CDATA Sections in <variable> When Casting Strings to Documents
You may also need to wrap element content when the input is a string of XML content that you need to cast to an XML document.
<input name="rssString" type="string"/>

<variable name="rssDoc" type="document"
output-cdata-section-elements ="title description" />

<assign fromvar="$rssString" outputvariable="$rssDoc"/>
Copyright © 2017 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback