将SQL OPENXML转换为XML节点值

时间:2015-05-06 11:24:16

标签: xml c#

任何人都可以帮助将以下内容从OPENXML转换为Node

protected virtual void ApplySqlXmlSetupSql()
{
  if (!this.query.HasFilterBySectionList && this.query.IgnorePermissions && !this.query.HasExcludeSectionList)
    return;
  StringBuilder sb = new StringBuilder();
  sb.Append("<xml>");
  if (this.query.HasFilterBySectionList || !this.query.IgnorePermissions)
    this.GetSectionIDXml(sb);
  if (this.query.HasExcludeSectionList)
    this.GetExcludeSectionIDXml(sb);
  sb.Append("</xml>");
  this.sb.Append("DECLARE @iXml int\n").Append("DECLARE @sectionIDs table (sectionID int not null primary key)\n").Append("DECLARE @excludeSectionIDs table (sectionID int not null primary key)\n").Append("EXECUTE [master].[dbo].[sp_xml_preparedocument] @iXml OUTPUT, ").Append("N'").Append(sb.ToString()).Append("'").Append("\n").Append("set nocount on\n");
  if (this.query.HasFilterBySectionList || !this.query.IgnorePermissions)
    this.sb.Append("insert into @sectionIDs ").Append("SELECT a.sectionID FROM ").Append("OPENXML(@iXml, '/xml/SectionIDs/i', 2) ").Append("WITH ( sectionID int '.' ) AS a\n");
  if (this.query.HasExcludeSectionList)
    this.sb.Append("insert into @excludeSectionIDs ").Append("SELECT a.sectionID FROM ").Append("OPENXML(@iXml, '/xml/ExcludeSectionIDs/i', 2) ").Append("WITH ( sectionID int '.' ) AS a\n");
  this.sb.Append("set nocount off\n").Append("EXECUTE [master].[dbo].[sp_xml_removedocument] @iXml\n").Append("\n");
}

https://msdn.microsoft.com/en-GB/library/ms186918.aspx

https://msdn.microsoft.com/en-GB/library/ms188282.aspx

UPDATE

基本上sql归结为:

DECLARE @iXml int
DECLARE @sectionIDs table (sectionID int not null primary key)
DECLARE @excludeSectionIDs table (sectionID int not null primary key)
EXECUTE [master].[dbo].[sp_xml_preparedocument] @iXml OUTPUT, N''
set nocount on

insert into @sectionIDs SELECT a.sectionID FROM OPENXML(@iXml, '/xml/SectionIDs/i', 2) WITH ( sectionID int '.' ) AS a
insert into @excludeSectionIDs SELECT a.sectionID FROM OPENXML(@iXml, '/xml/ExcludeSectionIDs/i', 2) WITH ( sectionID int '.' ) AS a

set nocount off
EXECUTE [master].[dbo].[sp_xml_removedocument] @iXml

0 个答案:

没有答案
相关问题