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
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
在编程的道路上,一往无前,埋头狂奔。
[奔跑的人生] | [segmentfault] | [spring4all] | [csdn] | [掘金] | [OSChina] | [简书] | [知乎] | [51CTO]
[奔跑的人生] | [segmentfault] | [spring4all] | [csdn] | [掘金] | [OSChina] | [简书] | [知乎] | [51CTO]
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?