Retrieving String Content of a Complex Mixed Element Using XQuery

For example, there is xml:

<article-list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="3.xsd">
    <article section="physics">
        Increasing linear dynamic range of commercial digital photocamera
        <author>M. V. Konnik</author>
        <content>
            Methods of increasing linear optical dynamic range
        </content>
    </article>

      

My goal is to request the string content of an element article

. I.e:.

Increasing linear dynamic range of commercial digital photocamera

      

An obvious solution like this:

<!--xquery-->
{
for $article in doc("name.xml")//article-list/article
    where $article/receiving-date > xs:date("2005-01-01")
    return
        <article>
            {$article}
        </article>
}

      

Returns the whole tree article

, not just a string.

0


a source to share


1 answer


$ article is an element, not a node. To get the text (the text you want is actually the text node child of the $ node article), you just need to:



 {$article/text()}

      

0


a source







All Articles