我创建包含动态数据的一个元素 -
XQUERY
let $sttag:= concat('<', '/')
return concat ($sttag, "newTag")
上述XQuery返回输出作为</newTag
代替</newTag
。
它有什么办法用xquery打印“<”和“>”?
我创建包含动态数据的一个元素 -
XQUERY
let $sttag:= concat('<', '/')
return concat ($sttag, "newTag")
上述XQuery返回输出作为</newTag
代替</newTag
。
它有什么办法用xquery打印“<”和“>”?
我推荐使用XQuery's element constructors。您可以动态使用computed element constructor创建元素:
element book {
attribute isbn {"isbn-0060229357" },
element title { "Harold and the Purple Crayon"},
element author {
element first { "Crockett" },
element last {"Johnson" }
}
}
结果
<book isbn="isbn-0060229357">
<title>Harold and the Purple Crayon</title>
<author>
<first>Crockett</first>
<last>Johnson</last>
</author>
</book>
(例如,从W3C XQuery specs)
在你的情况,你可以使用
element newTag { ... }
这里是最多的插图构建一个元素动态的方式 - 这个名字是不是在编译时已知的,在每次执行一般是不同的:
let $name := translate(concat('N', current-time()), ':','_')
return
element {$name} {}
产生:
<N21_26_40.708-07_00/>
我只想补充一点,你的'newTag'也可以动态构造,例如'element {concat(“new”,“Tag”)} {...}'。 – joewiz 2012-04-20 21:07:15
我还想补充一点,您可以将XML元素直接放入xQuery中。我发现它比'element {}'语法更具可读性。当我需要动态创建元素时,我只使用'element {}'语法。 – 2012-12-20 02:27:34