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

    1. <tfoot id='kTDxY'></tfoot>

          <bdo id='kTDxY'></bdo><ul id='kTDxY'></ul>
        <legend id='kTDxY'><style id='kTDxY'><dir id='kTDxY'><q id='kTDxY'></q></dir></style></legend>
      1. <i id='kTDxY'><tr id='kTDxY'><dt id='kTDxY'><q id='kTDxY'><span id='kTDxY'><b id='kTDxY'><form id='kTDxY'><ins id='kTDxY'></ins><ul id='kTDxY'></ul><sub id='kTDxY'></sub></form><legend id='kTDxY'></legend><bdo id='kTDxY'><pre id='kTDxY'><center id='kTDxY'></center></pre></bdo></b><th id='kTDxY'></th></span></q></dt></tr></i><div id='kTDxY'><tfoot id='kTDxY'></tfoot><dl id='kTDxY'><fieldset id='kTDxY'></fieldset></dl></div>

      2. 预期 XML 解析分号 - 仅在替换 &amp; 时与 &

        时间:2023-06-07
          <bdo id='am1EG'></bdo><ul id='am1EG'></ul>
          • <i id='am1EG'><tr id='am1EG'><dt id='am1EG'><q id='am1EG'><span id='am1EG'><b id='am1EG'><form id='am1EG'><ins id='am1EG'></ins><ul id='am1EG'></ul><sub id='am1EG'></sub></form><legend id='am1EG'></legend><bdo id='am1EG'><pre id='am1EG'><center id='am1EG'></center></pre></bdo></b><th id='am1EG'></th></span></q></dt></tr></i><div id='am1EG'><tfoot id='am1EG'></tfoot><dl id='am1EG'><fieldset id='am1EG'></fieldset></dl></div>
          • <tfoot id='am1EG'></tfoot>
                <tbody id='am1EG'></tbody>

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

                1. <legend id='am1EG'><style id='am1EG'><dir id='am1EG'><q id='am1EG'></q></dir></style></legend>
                  本文介绍了预期 XML 解析分号 - 仅在替换 &amp; 时与 &amp;amp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有以下查询,它有效:

                  I have the following query, which works:

                  DECLARE @Combined VARCHAR(MAX)
                  
                  SET @Combined = 'mac cheese';
                  
                  DECLARE @KeyTable TABLE (Keyword VARCHAR(MAX))
                  INSERT INTO @KeyTable
                  SELECT @Combined
                  
                  IF OBJECT_ID('tempdb..#Temp') IS NOT NULL
                      DROP TABLE #Temp
                  
                  SELECT LTRIM(RTRIM(m.n.value('.[1]','varchar(8000)'))) AS Keyword
                      INTO #Temp
                  FROM
                  (
                  SELECT CAST('<XMLRoot><RowData>' + REPLACE(Keyword,',','</RowData><RowData>') + '</RowData></XMLRoot>' AS XML) AS x
                  FROM @KeyTable
                  )t
                  CROSS APPLY x.nodes('/XMLRoot/RowData')m(n);
                  
                  SELECT * FROM #Temp
                  

                  当我尝试向 @Combined 添加一个&符号时,它给出了一个特殊字符错误:

                  When I try to add an ampersand to the @Combined it gives a special character error:

                  DECLARE @Combined VARCHAR(MAX)
                  
                  SET @Combined = 'mac & cheese';
                  
                  DECLARE @KeyTable TABLE (Keyword VARCHAR(MAX))
                  INSERT INTO @KeyTable
                  SELECT @Combined
                  
                  IF OBJECT_ID('tempdb..#Temp') IS NOT NULL
                      DROP TABLE #Temp
                  
                  SELECT LTRIM(RTRIM(m.n.value('.[1]','varchar(8000)'))) AS Keyword
                      INTO #Temp
                  FROM
                  (
                  SELECT CAST('<XMLRoot><RowData>' + REPLACE(Keyword,',','</RowData><RowData>') + '</RowData></XMLRoot>' AS XML) AS x
                  FROM @KeyTable
                  )t
                  CROSS APPLY x.nodes('/XMLRoot/RowData')m(n);
                  
                  SELECT * FROM #Temp
                  

                  所以我添加了一些代码来用 &amp 替换 & 号,但我得到了一个分号错误:

                  So I added some code to replace the ampersand with &amp and I get a semicolon error:

                  DECLARE @Combined VARCHAR(MAX)
                  
                  SET @Combined = 'mac & cheese'
                  
                  SET @Combined = REPLACE(@Combined, '&', '&amp')
                  
                  DECLARE @KeyTable TABLE (Keyword VARCHAR(MAX))
                  
                  INSERT INTO @KeyTable
                  SELECT @Combined;
                  
                  IF OBJECT_ID('tempdb..#Temp') IS NOT NULL
                      DROP TABLE #Temp
                  
                  SELECT LTRIM(RTRIM(m.n.value('.[1]','varchar(8000)'))) AS Keyword
                      INTO #Temp
                  FROM
                  (
                  SELECT CAST('<XMLRoot><RowData>' + REPLACE(Keyword,',','</RowData><RowData>') + '</RowData></XMLRoot>' AS XML) AS x
                  FROM @KeyTable
                  )t
                  CROSS APPLY x.nodes('/XMLRoot/RowData')m(n);
                  
                  SELECT * FROM #Temp
                  

                  我尝试将分号移动到不同的位置,甚至添加更多,但它不起作用.任何人都可以提供的任何帮助将不胜感激!

                  I've attempted moving the semicolon to various locations and even adding more but it just won't work. Any help anyone can provide would be appreciated!

                  推荐答案

                  不,你不应该开始自己替换特殊字符!

                  No, you should not start to replace special characters on your own!

                  下次您的字符串包含 <-> 并且会再次中断.

                  Next time your string contains a < or a -> and will break again.

                  FOR XML PATH() 为您完成繁重的工作:

                  Let FOR XML PATH() do the hard work for you:

                  SELECT 'This is pure text: ' + 'mac & cheese,<test1>,"test2"';
                  SELECT 'This is encoded: ' + (SELECT 'mac & cheese,<test1>,"test2"' AS [*] FOR XML PATH(''))
                  

                  第二个结果:这是编码:mac &amp;奶酪,&l​​t;test1>,&lt;test2&gt;

                  你唯一需要改变的是使用 (SELECT ... FOR XML PATH()) 而不是 naked Keyword>

                  The only thing you have to change, is to use (SELECT ... FOR XML PATH()) instead of the naked Keyword

                  DECLARE @KeyTable TABLE (Keyword VARCHAR(MAX))
                  INSERT INTO @KeyTable VALUES('mac & cheese,<test1>,"test2"');
                  
                  SELECT LTRIM(RTRIM(m.n.value('.[1]','varchar(8000)'))) AS Keyword
                  FROM
                  (
                  SELECT CAST('<XMLRoot><RowData>' + REPLACE((SELECT Keyword AS [*] FOR XML PATH('')),',','</RowData><RowData>') + '</RowData></XMLRoot>' AS XML) AS x
                  FROM @KeyTable
                  )t
                  CROSS APPLY x.nodes('/XMLRoot/RowData')m(n);
                  

                  这将隐式替换所有禁用字符...

                  This will replace all forbidden characters implicitly...

                  结果

                  mac & cheese
                  <test1>
                  "test2"
                  

                  这篇关于预期 XML 解析分号 - 仅在替换 &amp; 时与 &amp;amp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何将 XML 文件及其列名导入 SQL 表? 下一篇:sql server 上的 XML 解析

                  相关文章

                  最新文章

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

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

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

                  2. <tfoot id='vT1mU'></tfoot>