久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <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="qwawimqqmiuu" 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="qwawimqqmiuu" 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 字符串操作的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

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

                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",那么字符串我們認為這些真理是不言自明的"將變成我們這些真理是不言自明的".

                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."

                同樣,這個臟"字可以在任何節點中,并且標簽不會總是相同的.我需要編寫一個過程或觸發器來分析基于臟詞列表的 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 分解為每個節點一行的表格.該表需要一個 id 與該節點在粉碎的 XML 中的位置相對應,以便能夠寫回更改.

                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 將它們從帶有節點值的表中刪除.

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

                最后,您遍歷清理過的值并將它們一次一個節點寫回 XML,以用于實際修改的節點.

                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
                

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

                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>
                

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

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

                相關文檔推薦

                Can I figure out a list of databases and the space used by SQL Server instances without writing SQL queries?(我可以在不編寫 SQL 查詢的情況下找出數據庫列表和 SQL Server 實例使用的空間嗎?) - IT屋-程序員軟件開發
                How to create a login to a SQL Server instance?(如何創建對 SQL Server 實例的登錄?)
                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()?(為什么會出現“數據類型轉換錯誤?使用 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 應用程序設計——將文檔從 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="qwawimqqmiuu" 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>

                        • 主站蜘蛛池模板: 亚洲区视频 | 国产一区二区观看 | 欧美日韩一区精品 | 久久久福利 | 久久青 | 欧美一区成人 | 国产精品美女久久久久久久网站 | 久久亚洲综合 | 国产精品3区 | 国产在线视频一区 | 国产成人精品免费视频大全最热 | 日韩区| 亚洲在线观看视频 | 久久av一区二区 | 日韩在线中文 | 男女羞羞视频免费看 | 一二区视频 | 国产高清在线精品 | 日韩av免费在线电影 | 欧美激情精品久久久久久变态 | 亚洲精品久久 | 永久免费视频 | 日韩一区二区三区精品 | 亚洲精品久久久久久久久久久久久 | 久久99精品视频 | 日本一区二区三区精品视频 | 亚洲精品国产综合区久久久久久久 | 国产精品久久久久影院色老大 | 亚洲小说图片 | 亚州中文字幕 | 亚洲激情网站 | 亚洲欧美日韩精品久久亚洲区 | 欧美日韩一区二区三区不卡视频 | 国产成在线观看免费视频 | 蜜桃精品视频在线 | 中文字幕成人av | 成人欧美一区二区三区白人 | 免费黄色录像视频 | 欧美日本一区 | 伊人在线 | 国产免费xxx |