惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
V
V2EX - 技术
S
Secure Thoughts
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
S
Securelist
S
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
GRAHAM CLULEY
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
Intezer
Google Online Security Blog
Google Online Security Blog
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
The Cloudflare Blog
I
InfoQ
L
LangChain Blog
U
Unit 42
P
Proofpoint News Feed
S
Schneier on Security
S
Security Affairs
Y
Y Combinator Blog
T
Tenable Blog
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
量子位
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
GbyAI
GbyAI
AWS News Blog
AWS News Blog

博客园 - qjlyp

如何用Java 实现 Excel 表达式的解析(摘自:http://topic.csdn.net/t/20030408/17/1634982.html#) 群发UDP的性能测试 (摘自:http://www.cnblogs.com/trywebservice/archive/2008/02/19/1073642.html) 从底层了解ASP.NET体系结构 (http://www.cnblogs.com/rijing2004/archive/2007/09/14/howaspnetwork.html#8) 如何用C#编程方式批量对域控制器添加OU(http://topic.csdn.net/t/20051026/11/4351176.html) C# 高级编程(第3版)--Active Directory编程(http://blog.chinaunix.net/u/884/showart_230743.html) LDAP应用程序接口(http://www.networkdictionary.cn/rfc/rfc1823.php#6) 定制你的LDAP目录的Schema(http://www.infoxa.com/asp/tech_file/xxnr_tech_201.htm) 浅析.Net下Active Directory(AD)编程技术(from :http://www.zysun.com/ldap/21944.html) 活动目录.NET编程Tips(摘:http://www.lupaworld.com/22221/viewspace_17754.html) 应用软件人才体系图 针对构架师的.NET 3.0 框架介绍( 摘自:http://www.chinaaspx.com/dotnet/aspnet/20070811/3489.html) Rremoting 实现SQL Server 2005快速Web分页 让你的SQL数据库优化使之运行得更快 interoperate beneath C#基础概念二十五问 ASP.Net中利用CSS实现多界面两法【转自:中国站长站】 ASP.NET生成静态HTML页面并分别按年月目录存放[来自:中国站长站]
Solving problems while passing XML into a Stored Procedure
qjlyp · 2007-08-14 · via 博客园 - qjlyp

come from:http://www.codeproject.com/soap/XML_TO_StoredProcedure.asp

Introduction

Generally, when XML data is being passed to a stored procedure, it would contain the XML version and encoding information along with namespace declarations. This sometimes interferes with the XPath queries. Here is one way we can solve the problem.

Suppose the XML is like this:

<?xml version="1.0" encoding="utf-8" ?> 
<MESSAGE xmlns="https://tempuri.org">
<HEADER>
<TAG1>test</TAG1>
<TAG2></TAG2>
</HEADER>
<DETAILS>
<TAG1></TAG1>
<TAG2></TAG2>
</DETAILS>
</MESSAGE>

and the stored procedure:

create PROCEDURE ProcessXMLDocument

@xmlDoc varchar(8000)
AS
DECLARE @hDoc int
/*Load the document*/
EXEC sp_xml_preparedocument @hDoc OUTPUT, @xmlDoc
DECLARE @message varchar(10)

SELECT @message= [TAG1]
FROM OPENXML
(@hdoc,'//HEADER',2)
WITH
(TAG1 varchar(10))

When this XML is passed into the stored procedure, XPath queries would not always return the correct result. This query would not return anything.

Following code would solve the problem by removing the namespace tags:

Collapse

create PROCEDURE ProcessXMLDocument
@xmlDoc varchar(8000)
AS

DECLARE @hDoc int,
@NSEndPos int

/*Remove the xml declaration as it messes up the
document use the first end tag (>) as the marker for text removal*/

Select @NSEndPos = PATINDEX('%>%', @xmldoc) +1
Select @xmldoc = Substring(@xmldoc,@NSEndPos,Len(@xmldoc) - @NSEndPos +1)

/*Remove the Namespace as it messes up the document use
the first end tag (>) as the marker for text removal*/

Select @NSEndPos = PATINDEX('%>%', @xmldoc) +1
Select @xmldoc = '<MESSAGE>' + Substring(@xmldoc,
@NSEndPos,Len(@xmldoc) - @NSEndPos +1)

/*Load the document*/
EXEC sp_xml_preparedocument @hDoc OUTPUT, @xmlDoc
DECLARE @message varchar(10)

SELECT @message= [TAG1]
FROM OPENXML
(@hdoc,'//HEADER',2)
WITH
(TAG1 varchar(10))

posted on 2007-08-14 13:37  qjlyp  阅读(227)  评论()    收藏  举报