Note that there are some explanatory texts on larger screens.

plurals
  1. POPreserving HTML tags inside XQuery
    primarykey
    data
    text
    <p>I'm using eXist for a project at work, and I've run into a problem that I can't seem to figure out a solution for.</p> <p>I have an xquery script that is updating an existing document that is already in the database. Part of the data that needs to be updated contains HTML, specifically <code>&lt;p&gt;</code> and <code>&lt;/p&gt;</code> tags. I cannot get eXist/XQuery to stop escaping the HTML. It <em>needs</em> to be preserved in it's original form. Here's a very simple version of what I'm doing:</p> <pre><code>&lt;pre&gt; declare variable $raw-content := request:get-parameter('content', '') declare variable $content := local:clean($raw-content) &lt;/pre&gt; </code></pre> <p><code>local:clean</code> is the following function:</p> <pre><code>&lt;pre&gt; declare function local:clean($text) { let $text := util:parse($text) return $text }; &lt;/pre&gt; </code></pre> <p>Later on in the code I update a specific XML element</p> <pre><code>&lt;pre&gt; {update replace $n/sports-content/article/nitf/body/body.content with &lt;body.content&gt;{$content}&lt;/body.content&gt;} &lt;/pre&gt; </code></pre> <p>Now, this works perfect <em>if</em> I only pass in data wrapped in one set of tags (ie <code>&lt;p&gt;foo&lt;/p&gt;</code>). If I do <code>&lt;p&gt;foo&lt;/p&gt;&lt;p&gt;bar&lt;/p&gt;</code>, I get a null value placed in <code>$text</code>.</p> <p>I've been banging my head against the desk for a day and a half now trying to figure out why this doesn't work. Any help in solving this problem would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload