将XML应用程序从DB2 8.x迁移到Viper(5)

上一篇 / 下一篇  2008-04-24 21:15:57 / 个人分类:技术文章

重要事项:必须在路径的末尾指定 text()。这一步确保即使是空元素(即不具有现有文本节点的元素)也进行更新。如果省略了 text() 且不存在要替换的现有文本值,更新命令就会失败。

使用 XMLUpdate 追加子节点。

CallDB2XMLFUNCTIONS.XMLUPDATE (
'<updates namespaces="x:http://posample.org">
<update action="append" col="1" path="/x:customerinfo/x:addr">
<county>Santa Clara</county>
</update>
</updates>',
'Select info from XMLCustomer where cid=1006',
'update XMLCustomer set info=? where cid=1006',?,?);

注意:新节点 不在任何名称空间中。

使用 XMLUpdate 将更新的 XML 插入新行。

CallDB2XMLFUNCTIONS.XMLUPDATE (
'<updates namespaces="x:http://posample.org">
<update action="replace" col="1"
path="/x:customerinfo/x:name">
<name>Marja Soininen</name>
</update>
<update action="replace" col="1"
path="/x:customerinfo/@Cid">1008</update>
</updates>',
'Select info from XMLCustomer where cid=1006',
'insert into XMLCustomer (cid, info ) values (1008,

cast( ? as xml))',?,?);

使用 XMLUpdate 删除节点。

CallDB2XMLFUNCTIONS.XMLUPDATE (
'<updates namespaces="x:http://posample.org">
<update action="delete" col="1" path="/x:customerinfo/x:name"/>
</updates>',
'Select info from XMLCustomer where cid=1006',
'update XMLCustomer set info=? where cid=1006',?,?);

当更新元素中没有设置 @action 时,就默认执行替换操作。

CallDB2XMLFUNCTIONS.XMLUPDATE (
'<updates namespaces="x:http://posample.org">
<update col="1" path="//x:customerinfo[@Cid=1006]/x:phone">
<phone><areacode>910</areacode></phone>
</update>
</updates>',
'Select info from XMLCustomer where cid=1006',
'update XMLCustomer set info=? where cid=1006',?,?);

以下示例展示带有无效名称空间或带有没有前缀的名称空间的 XMLUpdate:

CallDB2XMLFUNCTIONS.XMLUPDATE (
'<updates namespaces="x:http://my.org">
<update col="1"
path="//x:customerinfo[@Cid=1006]/x:phone">
<phone><areacode>910</areacode></phone>
</update>
</updates>',
'Select info from XMLCustomer where cid=1006',
'update XMLCustomer set info=? where cid=1006',?,?);

该查询返回设置为 1 的错误,以及如下错误消息:

<error type='abort' action='replace' msg='Cannot find path
//x:customerinfo[@Cid=1006]/x:phone) in the XMLDocument'>

以下示例展示的 XMLUpdate 在更新元素中有一个遗漏的路径:

CallDB2XMLFUNCTIONS.XMLUPDATE (
'<updates > <update col="1"> (20+?)*32-? </update></updates>',
'Select info from XMLCustomer where cid=1006',
'update XMLCustomer set info=? where cid=1006',?,?);

该查询返回设置为 1 的错误,以及如下错误消息:

<error type='abort' action='null' msg='path not defined'></error>

使用相同名称空间中的新节点替换某个节点。

CallDB2XMLFUNCTIONS.XMLUPDATE (

'<updates namespaces="x:http://posample.org">
<update action="replace" col="1" path="/x:customerinfo/x:name">
<name xmlns="http://posample.org">
<fname>Marja</fname><lname>Soininen</lname>
</name>
</update>
</updates>',
'Select info from XMLCustomer where cid=1008',
'insert into XMLCustomer (cid, info ) values (1007,

cast( ? as xml))',?,?);

结束语

本文描述的更新存储过程允许对本机存储在数据库中的 XML 文档进行部分更新。下一篇文章将深度挖掘和具体研究新的 XML 支持对迁移现有基于 XML 的应用程序的重大意义。


TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-10-08  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 81311
  • 日志数: 24223
  • 建立时间: 2007-12-06
  • 更新时间: 2008-06-15

RSS订阅

Open Toolbar