Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print "<" and ">" using XQuery?

For example

I am creating an element with dynamic data -

XQUERY
let $sttag:=  concat('<', '/')
return concat ($sttag, "newTag")

above XQuery returns output as &lt;/newTag instead of </newTag.

it there any way to print "<" and ">" using xquery?

like image 334
dwarkesh Avatar asked Dec 03 '25 19:12

dwarkesh


2 Answers

Here is an illustration of the most dynamic way to construct an element -- the name isn't known at compile time and is generally different at every execution:

let $name := translate(concat('N', current-time()), ':','_')
  return
      element {$name} {}

produces:

<N21_26_40.708-07_00/>
like image 141
Dimitre Novatchev Avatar answered Dec 05 '25 09:12

Dimitre Novatchev


I recommend using XQuery's element constructors. You can create elements dynamically using a computed element constructor:

element book { 
    attribute isbn {"isbn-0060229357" }, 
    element title { "Harold and the Purple Crayon"},
    element author { 
        element first { "Crockett" }, 
        element last {"Johnson" }
    }
}

results in

<book isbn="isbn-0060229357">
    <title>Harold and the Purple Crayon</title>
    <author>
        <first>Crockett</first>
        <last>Johnson</last>
    </author>
</book>

(Example from the W3C XQuery specs)

In your case, you could use

element newTag { ... }
like image 27
tohuwawohu Avatar answered Dec 05 '25 08:12

tohuwawohu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!