SQL2008中的XML字段操作,与命名空间相关

 1  --  ================================================
 2  --  Proc Function : 测试2008中XML字段
 3  --  Create Date   : 2012-09-04
 4  --  Create User   : IsaacZhang
 5  --  Update User   : IsaacZhang
 6  --  ================================================
 7  select Authors
 8  declare  @data xml;
 9  set  @data  =  ' <?xml version="1.0"?>
10  <ArrayOfAuthor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
11    <Author>
12      <AuthorId xmlns="http://services.notefirst.com/Type/Author">6d3723e8-dbdc-4e40-bc40-e558d4631e1b</AuthorId>
13      <FirstName xmlns="http://services.notefirst.com/Type/Author">Alice</FirstName>
14      <LastName xmlns="http://services.notefirst.com/Type/Author">Baptista</LastName>
15      <MiddleName xmlns="http://services.notefirst.com/Type/Author">Ana</MiddleName>
16      <FullName xmlns="http://services.notefirst.com/Type/Author">Ana Alice Baptista</FullName>
17      <Email xmlns="http://services.notefirst.com/Type/Author" />
18      <Organization xmlns="http://services.notefirst.com/Type/Author" />
19      <BibliographyId xmlns="http://services.notefirst.com/Type/Author">343032de-9eb8-4a54-9529-02c7be601d1d</BibliographyId>
20      <IsOrganization xmlns="http://services.notefirst.com/Type/Author">false</IsOrganization>
21      <Order xmlns="http://services.notefirst.com/Type/Author">0</Order>
22      <Spell_LastName xmlns="http://services.notefirst.com/Type/Author" />
23      <Spell_FirstName xmlns="http://services.notefirst.com/Type/Author" />
24      <Spell_MiddleName xmlns="http://services.notefirst.com/Type/Author" />
25      <IsSpell xmlns="http://services.notefirst.com/Type/Author">false</IsSpell>
26      <FullNameEn xmlns="http://services.notefirst.com/Type/Author">Ana Alice Baptista</FullNameEn>
27    </Author>
28    <Author>
29      <AuthorId xmlns="http://services.notefirst.com/Type/Author">af4642cb-bf85-40d6-b613-f44b9932e527</AuthorId>
30      <FirstName xmlns="http://services.notefirst.com/Type/Author">Barbosa</FirstName>
31      <LastName xmlns="http://services.notefirst.com/Type/Author">Machado</LastName>
32      <MiddleName xmlns="http://services.notefirst.com/Type/Author">Altamiro</MiddleName>
33      <FullName xmlns="http://services.notefirst.com/Type/Author">Altamiro Barbosa Machado</FullName>
34      <Email xmlns="http://services.notefirst.com/Type/Author" />
35      <Organization xmlns="http://services.notefirst.com/Type/Author" />
36      <BibliographyId xmlns="http://services.notefirst.com/Type/Author">343032de-9eb8-4a54-9529-02c7be601d1d</BibliographyId>
37      <IsOrganization xmlns="http://services.notefirst.com/Type/Author">false</IsOrganization>
38      <Order xmlns="http://services.notefirst.com/Type/Author">0</Order>
39      <Spell_LastName xmlns="http://services.notefirst.com/Type/Author" />
40      <Spell_FirstName xmlns="http://services.notefirst.com/Type/Author" />
41      <Spell_MiddleName xmlns="http://services.notefirst.com/Type/Author" />
42      <IsSpell xmlns="http://services.notefirst.com/Type/Author">false</IsSpell>
43      <FullNameEn xmlns="http://services.notefirst.com/Type/Author">Altamiro Barbosa Machado</FullNameEn>
44    </Author>
45  </ArrayOfAuthor> ';
46   
47 
48     -- WITH XMLNAMESPACES ( N'' as a)
49 
50  /* select @data.query('declare default element namespace "http://services.notefirst.com/Type/Author";
51   (//FullName)');
52   select @data.value('(//FullName)[1]','varchar(200)');
53  select @data.query('Author'); */
54  declare  @isHas  varchar( 3);
55  select   @isHas  =  @data.exist( ' declare default element namespace "http://services.notefirst.com/Type/Author";//FullName ');
56  select  Cast( @isHas  as  int) + 1
57  -- select @data.exist('//author');
58 
59  -- select @data.nodes('//Author/FullName');
60 
61  select T.C.value( ' declare default element namespace "http://services.notefirst.com/Type/Author";(../FullName)[1] ', ' varchar(200) '
62  as authors
63  from  @data.nodes( ' declare default element namespace "http://services.notefirst.com/Type/Author";(//FullName) 'as T(C)
64 
65  -- select top 10 * from dbo.Bibliography

转载于:https://www.cnblogs.com/zhangpan1244/archive/2012/09/04/2669884.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值