本文介紹了如何在 XML 中向我的根添加常量?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
這是我生成 XML 的查詢:
This is my query that generates an XML:
SELECT [a] a
,[b] b
,[c] c
,[d] d
,[e] e
,[f] f
,[g] g
FROM test
ORDER BY 1
FOR XML PATH('a'), ROOT('ROOT'), ELEMENTS XSINIL
生成的 XML 以這個根開始:
The XML generated starts with this root:
我的目標是擁有一個具有更多屬性的根
My goal is to have a root with more attributes
這個屬性就像我想附加到我的根的常量(它們不是來自 select 的列).它們將被修復,無論選擇什么
This attributes are like constants (thet are not columns from select) that I want to append to my root. They will be fixed, whatever will be the select
可以嗎?
推薦答案
這是一個概念性示例.請試一試.
Here is a conceptual example. Please give it a shot.
SQL
-- DDL and sample data population, start
DECLARE @tbl TABLE (ID INT IDENTITY PRIMARY KEY, city VARCHAR(30));
INSERT INTO @tbl (city) VALUES
('Miami'),
('Orlando');
-- DDL and sample data population, end
SELECT 'SIN_OPE' AS [@cod_1], '08' AS [@cod_2], '12' AS [@num_reg]
, 'yyyyyyyyyyyyyyyyyyy.xsd' AS [@xsi:noNamespaceSchemaLocation]
, (
SELECT *
FROM @tbl
FOR XML PATH('r'), TYPE
)
FOR XML PATH('root'), TYPE, ELEMENTS XSINIL;
輸出
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" cod_1="SIN_OPE"
cod_2="08" num_reg="12"
xsi:noNamespaceSchemaLocation="yyyyyyyyyyyyyyyyyyy.xsd">
<r>
<ID>1</ID>
<city>Miami</city>
</r>
<r>
<ID>2</ID>
<city>Orlando</city>
</r>
</root>
這篇關于如何在 XML 中向我的根添加常量?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!