示例环境
在考虑如何查询包含名称空间的 XML 数据之前,需要一些示例数据。为此,我将使用 DB2 V9 来存储和查询关于业务伙伴的 XML 数据,将在一个 PARTNERS 表中维护该数据。如果您打算跟随我进行实践,那么就需要在一个 DB2 UTF-8 数据库中创建该表。
清单 4 中的脚本创建 PARTNERS 表,并插入一些行到该表中(每个行包含一个 XML 文档):
清单 4. 创建一个示例表并为之填充数据的脚本create table partners (id int primary key not null, status varchar(10), details xml);
insert into partners values (111, 'Gold',
'<company type="public">
<name>Acme Tech</name>
<specialty>Technology</specialty>
<contact>
<name>John Smith</name>
<title> VP, Business Development </title>
<email>js@us.acme_tech.com</email>
</contact>
</company>');
insert into partners values (200, 'Silver',
'<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>');
insert into partners values (222, 'Gold',
'<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>');
insert into partners values (333, 'Silver',
'<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>');
insert into partners values (444, 'Silver',
'<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>');
相关专题
- (3663篇文章)SQL Server 索引和查询专题
- (1621篇文章)XML详解
- (651篇文章)开发应用
- (908次浏览)XML基础教程
- (752次浏览)XML简介
- (741次浏览)如何读取XML文件内容
- (634次浏览)XML与面向Web的数据挖掘技术
- (521次浏览)了解 XML实现通用的数据访问
- (501次浏览)XML的简单读取与写入
- (447次浏览)XML入门精解之文件格式定义(DTD)
- (375次浏览)DOM的结构
- (361次浏览)XML Spy实例教程
- (354次浏览)XML入门之11问答



