c# sql查询为xml中的元素添加属性
本文关键字:元素 添加 属性 xml sql 查询 | 更新日期: 2023-09-27 17:54:28
我想通过从XML_TAGS
表中获取标记和从MAPPED_TAGS_ATTRIBUTES
表中获取属性来显示XML文件-类似于<element attributes></element>
:
String sql = "SELECT Dtd_Tag,Dtd_Attribute_Name
FROM Xml_Tags,
Mapped_Tags_Attributes
WHERE Mapped_Tags_Attributes.Pdf_Tag = Xml_Tags.Pdf_Tag
ORDER BY Mapped_Tags_Attributes.Pdf_Tag
FOR XML AUTO";
查询:
select
c.CustomerId as "@Id",
c.AcountNumber as "@AcountNumber"
from Customer c
for xml path('Customer'), root('Customers')
结果:<Customers>
<Customer Id="1" AccountNumber="X120" />
<Customer Id="2" AccountNumber="X121" />
</Customers>