xquerymarklogicentityreference

XQuery Invalid entity reference error caused by "&" entity reference


I'm trying to run this line xdmp:unquote(concat('<info>', string( $paragraph) , '</info>')) but I've got the following error: xdmp:unquote("<info>LEARNING &amp; MEMORY</info>") -- Invalid entity reference " " at line 1. It seems like this entity reference &amp; is causing the problem. I tried to remove it using replace function but it still present. What should I do?


Solution

  • I am assuming that you have something like this-

    let $paragraph := <p>LEARNING &amp; MEMORY</p>
    return
    xdmp:unquote(fn:concat('<info>', fn:string($paragraph),'</info>'))
    

    And that the result you want is XML that looks like-

    <info>LEARNING & MEMORY</info>
    

    The ampersand is definitely the issue and the workaround is to use the "repair-full" option. This example works:

    let $paragraph := <p>LEARNING &amp; MEMORY</p>
    let $contents := xdmp:unquote($paragraph, "", "repair-full")
    return
    <info>{$contents}</info>