本文介紹了如何在 SQL 中拆分具有相同子子名稱的兩個 xml 標簽的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我創建了一個腳本,它從 SQL 中的表中獲取數據并生成 XML 輸出.父、子和子子標簽對于 2 個標簽都是相同的.SQL 腳本將它們作為一個 XML 值而不是 2 輸出.
I have created a script which takes data from a table in SQL and generates an XML output. The parent, child and sub-child tags are all the same which for 2 tags. The SQL script is outputting them as one XML value instead of 2.
SELECT
Request.TransactionRef AS [RequestHeader/RequestID],
'Deal.Trial' AS [RequestHeader/Action],
'DoDealValidate' AS [RequestHeader/ActionFlags/Flag],
'DoDealDerive' AS [RequestHeader/ActionFlags/Flag]
目前的結果是:
<ActionFlags>
<Flag>DoDealValidateDoDealDerive</Flag>
</ActionFlags>
<ActionFlags>
<Flag>DoDealValidate</Flag>
<Flag>DoDealDerive</Flag>
</ActionFlags>
推薦答案
只需在中間放置一些空:
SELECT
'blah' AS [RequestHeader/RequestID],
'Deal.Trial' AS [RequestHeader/Action],
'DoDealValidate' AS [RequestHeader/ActionFlags/Flag],
NULL AS [RequestHeader/ActionFlags],
'DoDealDerive' AS [RequestHeader/ActionFlags/Flag]
FOR XML PATH('row');
背景:
引擎通過 SELECT 的列運行并一個接一個地構建它們.
The engine is running through the SELECT's columns and builds them one after the other.
- 好吧,有一個
要打開 - 并且有一個
要打開 - 再次
,還是打開的,沒什么 - 下面還有
...哦,我們必須關閉
并打開一個新的 - 等等...
- Well, there is a
<RequestHeader>
to open - and there is a
<RequestID>
to open - Again the
<RequestHeader>
, still open, nothin to to - and there is
<Action>
below... Oh, we must close the<RequestID>
and open a new<Action>
- and so on...
在您的代碼中,
仍然是打開的,因此內容被寫入到 open 元素中.
In your code the <Flag>
is still open, therefore the content is written into the open element.
我的改變會讓引擎思考
- 啊,我們上移一層,所以我們先關閉
...哎呀,沒什么可寫的... - 現在
<Flag>
有一些東西,它不再打開了,我們必須重新打開一個(新的)
節點立> - 等等...
- Ah, we move up one level, so we close the
<Flag>
first... Oops, there's nothing to write... - Now there is something for
<Flag>
, which is not open anymore, we have to re-open a (new)<Flag>
node - and so on...
這篇關于如何在 SQL 中拆分具有相同子子名稱的兩個 xml 標簽的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!