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

如何在sql中為xml的所有子節點添加屬性

how to add attribute for all subnodes of the xml in sql(如何在sql中為xml的所有子節點添加屬性)
本文介紹了如何在sql中為xml的所有子節點添加屬性的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在變量@xml中有一個像下面這樣的xml

I have a xml like below in a variable @xml

<ContentTemplate>
  <Tab Title="Lesson">
    <Section Title="Lesson Opening" />
    <Section Title="Lesson/Activity" />
  </Tab>
  <Tab Title="Wrap Up and Assessment">
    <Section Title="Lesson Closing" />
    <Section Title="Tracking Progress/Daily Assessment" />
  </Tab>
  <Tab Title="Differentiated Instruction">
    <Section Title="Strategies - Keyword" />
    <Section Title="Strategies – Text" />
    <Section Title="Resources" />
    <Section Title="Acceleration/Enrichment" />
  </Tab>
  <Tab Title="District Resources">
    <Section Title="Related Content Items" />
    <Section Title="Other" />
  </Tab>
</ContentTemplate>

我想為上述 xml 中的所有選項卡節點插入一個屬性..輸出應如下所示:

I want to insert an attribute for all tab nodes in the above xml.. the output should be like below:

<ContentTemplate>
      <Tab Title="Lesson" PortletName="CommunitiesViewer">
        <Section Title="Lesson Opening" />
        <Section Title="Lesson/Activity" />
      </Tab>
      <Tab Title="Wrap Up and Assessment" PortletName="CommunitiesViewer">
        <Section Title="Lesson Closing" />
        <Section Title="Tracking Progress/Daily Assessment" />
      </Tab>
      <Tab Title="Differentiated Instruction" PortletName="CommunitiesViewer">
        <Section Title="Strategies - Keyword" />
        <Section Title="Strategies – Text" />
        <Section Title="Resources" />
        <Section Title="Acceleration/Enrichment" />
      </Tab>
      <Tab Title="District Resources" PortletName="CommunitiesViewer">
        <Section Title="Related Content Items" />
        <Section Title="Other" />
      </Tab>
    </ContentTemplate>

我嘗試了下面的代碼來得到上面的xml

i tried the following code to get the above xml

set @xml.modify( 'insert attribute PortletName {sql:variable("@PortletName")} into (ContentTemplate/Tab)[1]')

它只是更新第一個子節點.

its just update the first sub node.

如何更新xml的所有子節點..

how to update all the sub nodes of the xml..

提前致謝

推薦答案

變量中的 XML

DECLARE @xml XML=
N'<ContentTemplate>
  <Tab Title="Lesson">
    <Section Title="Lesson Opening" />
    <Section Title="Lesson/Activity" />
  </Tab>
  <Tab Title="Wrap Up and Assessment">
    <Section Title="Lesson Closing" />
    <Section Title="Tracking Progress/Daily Assessment" />
  </Tab>
  <Tab Title="Differentiated Instruction">
    <Section Title="Strategies - Keyword" />
    <Section Title="Strategies – Text" />
    <Section Title="Resources" />
    <Section Title="Acceleration/Enrichment" />
  </Tab>
  <Tab Title="District Resources">
    <Section Title="Related Content Items" />
    <Section Title="Other" />
  </Tab>
</ContentTemplate>';

1) FLWOR

.modify() 語句允許您更改 XML 中的一個合適的點,但是您需要多次調用才能更改許多位置.FLWOR 允許您重新構建 XML:

1) FLWOR

The .modify()-statement allows you to change one decent point in your XML, but you'd need many calls to change many places. FLWOR allows you to re-build the XML out of itself:

SET @xml=@xml.query(
'<ContentTemplate>
{
for $t in /ContentTemplate/Tab
   return 
   <Tab Title="{$t/@Title}" PortletName="CommunitiesViewer">
   {$t/*}
   </Tab>
}
</ContentTemplate>');

SELECT @xml

2) 使用 SELECT ... FOR XML PATH()

重建

你會用這種方法達到同樣的效果:再次重建 XML,但這次它被切碎并用作新的 SELECT ... FOR XML PATH

SELECT tb.value('@Title','nvarchar(max)') AS [@Title]
      ,'CommunitiesViewer' AS [@PortletName]
      ,tb.query('*')
FROM @xml.nodes('/ContentTemplate/Tab') AS A(tb)
FOR XML PATH('Tab'),ROOT('ContentTemplate')

這篇關于如何在sql中為xml的所有子節點添加屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 嫩草一区二区三区 | 日韩爱爱网 | 日韩喷潮| 亚洲欧洲在线观看视频 | 亚洲巨乳自拍在线视频 | 永久免费av| 国产一级网站 | 亚洲国产精品一区二区久久 | 欧美一区永久视频免费观看 | 精品一区二区在线视频 | av天天看| 国产精品久久久久久久免费观看 | 欧美二区在线 | 欧美三级网站 | 欧美日韩一区二区三区在线观看 | 日韩国产欧美在线观看 | 亚洲国产精品一区二区三区 | 麻豆成人在线视频 | 范冰冰一级做a爰片久久毛片 | 国产精品中文字幕在线 | 综合一区二区三区 | 久久久久国产一区二区 | 免费一区| 久久国产精品99久久久久久丝袜 | 日本精品视频在线 | 91av视频| 中文在线播放 | 人操人免费视频 | 国产精品美女久久久久久免费 | 一区二区在线 | 91精品久久久 | 中文字幕日韩欧美一区二区三区 | 中文字幕在线一区 | 精品国产乱码久久久久久蜜退臀 | 色婷婷亚洲国产女人的天堂 | 欧美黄a | 欧美性tv | 九色在线观看 | 成人网址在线观看 | 亚洲精品国产一区 | 婷婷五月色综合香五月 |