pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <legend id='if6EO'><style id='if6EO'><dir id='if6EO'><q id='if6EO'></q></dir></style></legend>

    1. <i id='if6EO'><tr id='if6EO'><dt id='if6EO'><q id='if6EO'><span id='if6EO'><b id='if6EO'><form id='if6EO'><ins id='if6EO'></ins><ul id='if6EO'></ul><sub id='if6EO'></sub></form><legend id='if6EO'></legend><bdo id='if6EO'><pre id='if6EO'><center id='if6EO'></center></pre></bdo></b><th id='if6EO'></th></span></q></dt></tr></i><div class="tv7h5nh" id='if6EO'><tfoot id='if6EO'></tfoot><dl id='if6EO'><fieldset id='if6EO'></fieldset></dl></div>
      <tfoot id='if6EO'></tfoot>

      <small id='if6EO'></small><noframes id='if6EO'>

        <bdo id='if6EO'></bdo><ul id='if6EO'></ul>

      SQL Server XML 字符串操作

      SQL Server XML String Manipluation(SQL Server XML 字符串操作)
      <legend id='lACFd'><style id='lACFd'><dir id='lACFd'><q id='lACFd'></q></dir></style></legend>

      <i id='lACFd'><tr id='lACFd'><dt id='lACFd'><q id='lACFd'><span id='lACFd'><b id='lACFd'><form id='lACFd'><ins id='lACFd'></ins><ul id='lACFd'></ul><sub id='lACFd'></sub></form><legend id='lACFd'></legend><bdo id='lACFd'><pre id='lACFd'><center id='lACFd'></center></pre></bdo></b><th id='lACFd'></th></span></q></dt></tr></i><div class="tplj7p5" id='lACFd'><tfoot id='lACFd'></tfoot><dl id='lACFd'><fieldset id='lACFd'></fieldset></dl></div>

      <small id='lACFd'></small><noframes id='lACFd'>

        <bdo id='lACFd'></bdo><ul id='lACFd'></ul>

              <tfoot id='lACFd'></tfoot>
                <tbody id='lACFd'></tbody>

              • 本文介紹了SQL Server XML 字符串操作的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                限時送ChatGPT賬號..

                讓我聲明我是 XML 新手.也就是說,我的問題是我有一個創(chuàng)建 XML 數(shù)據(jù)的 SQL Server,并將其放入一個必須通過安全門到達(dá)另一臺服務(wù)器的文件中.門有幾個臟"詞的列表,如果包含這些詞,將導(dǎo)致文件失敗.我需要的是一種讓 SQL 搜索 XML 數(shù)據(jù)、每個節(jié)點(diǎn)的方法,如果存在臟"值,則將其刪除(替換為空白).XML 不是強(qiáng)類型的,臟"字可能是較長字符串的一部分.在這種情況下,字符串的其余部分必須保持完整.

                Let me state I am an XML novice. That said, my issue is I have a SQL Server that creates XML data, and places that into a file that must pass through a security gate to another server. The gate has a list of several "dirty"words that will cause the files to fail if they are included. What I need, is a way for SQL to search the XML data, every node, and if the "dirty" value is present, strip it out (replace with blank). The XML is not strongly typed, and the "dirty"word could possibly be part of a longer string. In that case, the rest of the string must remain intact.

                例如,如果臟"字是hold",那么字符串我們認(rèn)為這些真理是不言自明的"將變成我們這些真理是不言自明的".

                For example, if the "dirty" word is "hold," the string "We hold these truths to be self evident" would become "We these truths to be self evident."

                同樣,這個臟"字可以在任何節(jié)點(diǎn)中,并且標(biāo)簽不會總是相同的.我需要編寫一個過程或觸發(fā)器來分析基于臟詞列表的 XML 值來清理它.

                Again, this "dirty" word could be in any node, and the tags will not always be the same. I need to write a procedure or trigger that analyzes the XML value based on the dirty word list to clean it up.

                推薦答案

                將 XML 分解為每個節(jié)點(diǎn)一行的表格.該表需要一個 id 與該節(jié)點(diǎn)在粉碎的 XML 中的位置相對應(yīng),以便能夠?qū)懟馗?

                Shred the XML to a table with one row for each node. The table needs an id that corresponds to the position of the node in the shredded XML to be able to write back the changes.

                將你的壞詞放在一個表中,對于每個詞,使用 replace 將它們從帶有節(jié)點(diǎn)值的表中刪除.

                Have your bad words in a table and for each word use replace to remove them from the table with the nodes values.

                最后,您遍歷清理過的值并將它們一次一個節(jié)點(diǎn)寫回 XML,以用于實(shí)際修改的節(jié)點(diǎn).

                Finally you loop through the cleaned values and write them back to the XML one node at a time for the nodes that was actually modified.

                -- A table to hold the bad words
                declare @BadWords table
                (
                  ID int identity,
                  Value nvarchar(10)
                )
                
                -- These are the bad ones.
                insert into @BadWords values
                ('one'),
                ('three'),
                ('five'),
                ('hold')
                
                -- XML that needs cleaning
                declare @XML xml = '
                <root>
                  <itemone ID="1one1">1one1</itemone>
                  <itemtwo>2two2</itemtwo>
                  <items>
                    <item>1one1</item>
                    <item>2two2</item>
                    <item>onetwothreefourfive</item>
                  </items>
                  <hold>We hold these truths to be self evident</hold>
                </root>
                '
                
                -- A helper table to hold the values to modify
                declare @T table
                (
                  ID int identity,
                  Pos int,
                  OldValue nvarchar(max),
                  NewValue nvarchar(max),
                  Attribute bit
                )
                
                -- Get all attributes from the XML
                insert into @T(Pos, OldValue, NewValue, Attribute)
                select row_number() over(order by T.N),
                       T.N.value('.', 'nvarchar(max)'),
                       T.N.value('.', 'nvarchar(max)'),
                       1
                from @XML.nodes('//@*') as T(N)
                
                -- Get all values from the XML
                insert into @T(Pos, OldValue, NewValue, Attribute)
                select row_number() over(order by T.N),
                       T.N.value('text()[1]', 'nvarchar(max)'),
                       T.N.value('text()[1]', 'nvarchar(max)'),
                       0
                from @XML.nodes('//*') as T(N)
                
                declare @ID int
                declare @Pos int
                declare @Value nvarchar(max)
                declare @Attribute bit
                
                -- Remove the bad words from @T, one bad word at a time
                select @ID = max(ID) from @BadWords
                while @ID > 0
                begin
                  select @Value = Value
                  from @BadWords
                  where ID = @ID
                
                  update @T
                  set NewValue = replace(NewValue, @Value, '')
                
                  set @ID -= 1
                end
                
                -- Write the cleaned values back to the XML
                select @ID = max(ID) from @T
                while @ID > 0
                begin
                  select @Value = nullif(NewValue, OldValue),
                         @Attribute = Attribute,
                         @Pos = Pos
                  from @T
                  where ID = @ID
                
                  print @Attribute
                
                  if @Value is not null
                    if @Attribute = 1  
                      set @XML.modify('replace value of ((//@*)[sql:variable("@Pos")])[1] 
                                       with sql:variable("@Value")')
                    else
                      set @XML.modify('replace value of ((//*)[sql:variable("@Pos")]/text())[1] 
                                           with sql:variable("@Value")')
                  set @ID -= 1
                end
                
                select @XML
                

                注意:在某些情況下,上面的代碼不會處理修改本身產(chǎn)生錯誤值的值.

                Note: In some cases the code above will not deal with values where the modification itself creates the bad value.

                <item>fioneve</item>
                

                將被修改為

                <item>five</item>
                

                這篇關(guān)于SQL Server XML 字符串操作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                Can I figure out a list of databases and the space used by SQL Server instances without writing SQL queries?(我可以在不編寫 SQL 查詢的情況下找出數(shù)據(jù)庫列表和 SQL Server 實(shí)例使用的空間嗎?) - IT屋-程序員軟件開發(fā)
                How to create a login to a SQL Server instance?(如何創(chuàng)建對 SQL Server 實(shí)例的登錄?)
                How to know the version and edition of SQL Server through registry search(如何通過注冊表搜索知道SQL Server的版本和版本)
                Why do I get a quot;data type conversion errorquot; with ExecuteNonQuery()?(為什么會出現(xiàn)“數(shù)據(jù)類型轉(zhuǎn)換錯誤?使用 ExecuteNonQuery()?)
                How to show an image from a DataGridView to a PictureBox?(如何將 DataGridView 中的圖像顯示到 PictureBox?)
                WinForms application design - moving documents from SQL Server to file storage(WinForms 應(yīng)用程序設(shè)計(jì)——將文檔從 SQL Server 移動到文件存儲)
                      <tbody id='Rtqeg'></tbody>

                    <small id='Rtqeg'></small><noframes id='Rtqeg'>

                      <bdo id='Rtqeg'></bdo><ul id='Rtqeg'></ul>
                      <tfoot id='Rtqeg'></tfoot>

                      <i id='Rtqeg'><tr id='Rtqeg'><dt id='Rtqeg'><q id='Rtqeg'><span id='Rtqeg'><b id='Rtqeg'><form id='Rtqeg'><ins id='Rtqeg'></ins><ul id='Rtqeg'></ul><sub id='Rtqeg'></sub></form><legend id='Rtqeg'></legend><bdo id='Rtqeg'><pre id='Rtqeg'><center id='Rtqeg'></center></pre></bdo></b><th id='Rtqeg'></th></span></q></dt></tr></i><div class="nj57h7r" id='Rtqeg'><tfoot id='Rtqeg'></tfoot><dl id='Rtqeg'><fieldset id='Rtqeg'></fieldset></dl></div>

                        • <legend id='Rtqeg'><style id='Rtqeg'><dir id='Rtqeg'><q id='Rtqeg'></q></dir></style></legend>

                        • 主站蜘蛛池模板: OLChemim试剂-ABsciex耗材-广州市自力色谱科仪有限公司 | 阿米巴企业经营-阿米巴咨询管理-阿米巴企业培训-广东键锋企业管理咨询有限公司 | 回转支承-转盘轴承-回转驱动生产厂家-洛阳隆达轴承有限公司 | 玉米深加工机械,玉米加工设备,玉米加工机械等玉米深加工设备制造商-河南成立粮油机械有限公司 | 酒店品牌设计-酒店vi设计-酒店标识设计【国际级】VI策划公司 | 外贸资讯网 - 洞悉全球贸易,把握市场先机 | 电动液压篮球架_圆管地埋式篮球架_移动平箱篮球架-强森体育 | 兰州UPS电源,兰州山特UPS-兰州万胜商贸| 加气混凝土砌块设备,轻质砖设备,蒸养砖设备,新型墙体设备-河南省杜甫机械制造有限公司 | 热处理温控箱,热处理控制箱厂家-吴江市兴达电热设备厂 | MOOG伺服阀维修,ATOS比例流量阀维修,伺服阀维修-上海纽顿液压设备有限公司 | 淋巴细胞分离液_口腔医疗器材-精欣华医疗器械(无锡)有限公司 | 千淘酒店差旅平台-中国第一家针对TMC行业的酒店资源供应平台 | 土壤检测仪器_行星式球磨仪_土壤团粒分析仪厂家_山东莱恩德智能科技有限公司 | 碳化硅,氮化硅,冰晶石,绢云母,氟化铝,白刚玉,棕刚玉,石墨,铝粉,铁粉,金属硅粉,金属铝粉,氧化铝粉,硅微粉,蓝晶石,红柱石,莫来石,粉煤灰,三聚磷酸钠,六偏磷酸钠,硫酸镁-皓泉新材料 | 语料库-提供经典范文,文案句子,常用文书,您的写作得力助手 | 细沙回收机-尾矿干排脱水筛设备-泥石分离机-建筑垃圾分拣机厂家-青州冠诚重工机械有限公司 | 多物理场仿真软件_电磁仿真软件_EDA多物理场仿真软件 - 裕兴木兰 | 可程式恒温恒湿试验箱|恒温恒湿箱|恒温恒湿试验箱|恒温恒湿老化试验箱|高低温试验箱价格报价-广东德瑞检测设备有限公司 | 氧氮氢联合测定仪-联测仪-氧氮氢元素分析仪-江苏品彦光电 | 精准猎取科技资讯,高效阅读科技新闻_科技猎 | 北京企业宣传片拍摄_公司宣传片制作-广告短视频制作_北京宣传片拍摄公司 | 金库门,金库房,金库门厂家,金库门价格-河北特旺柜业有限公司 | 鲁尔圆锥接头多功能测试仪-留置针测试仪-上海威夏环保科技有限公司 | 天津仓储物流-天津电商云仓-天津云仓一件代发-博程云仓官网 | 全自动翻转振荡器-浸出式水平振荡器厂家-土壤干燥箱价格-常州普天仪器 | 代办建筑资质升级-建筑资质延期就找上海国信启航 | 南汇8424西瓜_南汇玉菇甜瓜-南汇水蜜桃价格 | 领袖户外_深度旅游、摄影旅游、小团慢旅行、驴友网 | 拉力机-拉力试验机-万能试验机-电子拉力机-拉伸试验机-剥离强度试验机-苏州皖仪实验仪器有限公司 | 钢格板|镀锌钢格板|热镀锌钢格板|格栅板|钢格板|钢格栅板|热浸锌钢格板|平台钢格板|镀锌钢格栅板|热镀锌钢格栅板|平台钢格栅板|不锈钢钢格栅板 - 专业钢格板厂家 | 铝单板_铝窗花_铝单板厂家_氟碳包柱铝单板批发价格-佛山科阳金属 | 储能预警-储能消防系统-电池舱自动灭火装置-四川千页科技股份有限公司官网 | pbt头梳丝_牙刷丝_尼龙毛刷丝_PP塑料纤维合成毛丝定制厂_广州明旺 | 气力输送_输送机械_自动化配料系统_负压吸送_制造主力军江苏高达智能装备有限公司! | 金属清洗剂,防锈油,切削液,磨削液-青岛朗力防锈材料有限公司 | 深圳湾1号房价_深圳湾1号二手房源 | 上海新光明泵业制造有限公司-电动隔膜泵,气动隔膜泵,卧式|立式离心泵厂家 | 光栅尺厂家_数显表维修-苏州泽升精密机械 | 超细|超微气流粉碎机|气流磨|气流分级机|粉体改性机|磨粉机|粉碎设备-山东埃尔派粉体科技 | 汽车润滑油厂家-机油/润滑油代理-高性能机油-领驰慧润滑科技(河北)有限公司 |