简体   繁体   English

C# sql 查询为 xml 中的元素添加属性

[英]C# sql query to add attributes for the elements in xml

I want to display the XML file by taking tag from the XML_TAGS table, and attributes from the MAPPED_TAGS_ATTRIBUTES table - something like <element attributes></element> :我想通过从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"; 

Query:询问:

select
    c.CustomerId as "@Id",
    c.AcountNumber as "@AcountNumber"
from Customer c
for xml path('Customer'), root('Customers')

Result:结果:

<Customers>
   <Customer Id="1" AccountNumber="X120" />
   <Customer Id="2" AccountNumber="X121" />
</Customers>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM