On Mon, 2013-12-02 at 15:29 -0500, Erol Akarsu wrote:[...]
> I would like to generate CDATA of one xmk construct like this.
> let $allfs := <record>Watch out that if $f1 (say) contains the string ]]> you'd be liable to a
> <name>{$name}</name>
> <features>
> <![CDATA[
> <h3>Features:</h3>
> <br/>
> <ul>
> <li>{$f1}</li>
> <li>{$f2}</li>
> <li>{$f3}</li>
> </ul>
> ]]>
> </features>
> </record>
cdata injection attack.
Having said that, no, I'd probably write an e() function,
declare function my:e($name as xs:string, $content as xs:string)
as xs:string
{
return concat("<", $name, ">", $content, "</", $name, ">")
}
and use my:e("ul",
concat(my:e("li", $f1),
my:e("li", $f2),
my:e("li", $f3))
and so on. Which gives you slightly more checking.
The implementation will probably generate < and > rather than
CDATA; XML says they're equivalent.
In XQuery 3 there's a per-element serialization option for CDATA
sections,
http://www.w3.org/TR/xslt-xquery-serialization-30/#XML_CDATA-SECTION-ELEMENTS
so if BaseX implements that you have a way to get closer to what you
want, perhaps, e.g. for generating RSS. However, you'd still need to
construct a string containing "<h1>" etc.
Liam
--
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml