查询包含名称空间的XML数据

http://tech.ddvip.com   2007年07月03日    社区交流

内容摘要:如果想学习关于 XQuery 与 SQL/XML 的基础以外的更多知识,那么必须理解文档和消息中的 XML 名称空间对查询的语义的影响。否则,就可能收到意外的结果。幸运的是,学习如何查询包含名称空间的 XML 文档并不难。本文提供了一些例子来帮助您起步。

  基于 清单 4 中的内容,DB2 返回由四个 XML 记录组成的一个序列:

  清单 13. 上述 XQuery 的输出<company xmlns="urn:xmlns:saracco-sample:company1.0" type="public">
<name>
  Saturnia Ltd
</name>
<specialty>
  Technology
</specialty>
<contact>
  <name>
    Klaus Fischer
  </name>
  <title>
    Alliance Manager
  </title>
  <email>
    klausfischer@uk.saturnia.com
  </email>
</contact>
</company>
<co:company xmlns:co="urn:xmlns:saracco-sample:company1.0" type="private">
<name>
  Maribel Enterprises
</name>
<specialty>
  Public relations
</specialty>
<contact>
  <name>
    Maribel Payton
  </name>
  <title>
    CEO
  </title>
  <email>
    mpayton@maribelent.com
  </email>
</contact>
</co:company>
<co:company xmlns:co="urn:xmlns:saracco-sample:company1.0" type="public">
<co:name>
  Credo International Corp.
</co:name>
<co:specialty>
  Manufacturing
</co:specialty>
<person:contact xmlns:person="http://www.ibm.com/bogus/saracco-sample/person1.0">
  <person:name>
    Helen Rakai
  </person:name>
  <person:title>
    Director of Marketing
  </person:title>
  <person:email>
    helen_rakai@credointcorp.com
  </person:email>
</person:contact>
</co:company>
<co:company xmlns:co="urn:xmlns:saracco-sample:company1.0" type="private">
<co:name>
  Raymond Associates
</co:name>
<co:specialty>
  Consulting
</co:specialty>
<person:contact xmlns:person="http://www.ibm.com/bogus/saracco-sample/person2.0">
  <person:name>
    Raymond Sanchez
  </person:name>
  <person:title>
    Dr.
  </person:title>
  <job:title xmlns:job="http://www.ibm.com/bogus/saracco-sample/job1.0">
    President
  </job:title>
  <person:email>
    drsanchez@ca.rrs.com
  </person:email>
  <person:comments>
    Prefers short-term projects
  </person:comments>
</person:contact>
</co:company>

来源:ibm.com    作者:C. M. Saracco    责编:豆豆技术应用

正在加载评论...