想要动态创建 XML 元素 [英] Want to create XML element on the fly

查看:24
本文介绍了想要动态创建 XML 元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动态创建一个元素,我正在尝试下面的查询,但它给了我这个错误:SQL16031N XQuery 语言功能使用语法element {$first} { "Crockett" }, element last {不支持约翰逊"} } })"

I want to create an element on the fly, I'm trying below query but its giving me this error: SQL16031N XQuery language feature using syntax "element {$first} { "Crockett" }, element last {"Johnson" } } })" is not supported

你能帮帮我吗.

    XQUERY
let $first := concat('first','')
return (element book { 
    attribute isbn {"isbn-0060229357" }, 
    element title { "Harold and the Purple Crayon"},
    element author { 
        element {$first} { "Crockett" }, 
        element last {"Johnson" }
    }
})

推荐答案

DB2 XQuery 似乎不支持 计算元素构造函数,具有动态计算名称.如果可能名称的数量很少并且事先知道,您可以通过列出所有可能性来绕过该限制.由于 DB2 似乎也不支持 switch,我们必须使用 if/else 级联来实现:

It seems that DB2 XQuery doesn't support computed element constructors with a dynamically computed name. If the number of possible names is small and known in advance, you can get around that limitation by listing all the possibilities. As DB2 doesn't seem to support switch either, we'll have to do it with an if/else cascade:

XQUERY
let $first := 'firstA'
return (element book { 
    attribute isbn {"isbn-0060229357" }, 
    element title { "Harold and the Purple Crayon"},
    element author { 
        if($first eq 'firstA')
          then element firstA { "Crockett" }
        else if($first eq 'firstB')
          then element firstB { "Crockett" }
        else if($first eq 'firstC')
          then element firstC { "Crockett" }
        else (), 
        element last {"Johnson" }
    }
})

这篇关于想要动态创建 XML 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆