我想将我的数据表转换为 XML。我有两个类似的数据表。
我想像这样转换类似的。
<?xml version="1.0" encoding="utf-8"?>
<root>
<member>
<refid>1</refid>
<fname>Indocin</fname>
<lname>David</lname>
<activities>
<refid>1</refid>
<act>Swimming</act>
</activities>
<activities>
<refid>1</refid>
<act>running</act>
</activities>
<Date>2013-09-17T18:10:01.3452408+05:30</Date>
</member>
<member>
<refid>2</refid>
<fname>Indocin</fname>
<lname>David</lname>
<activities>
<refid>2</refid>
<act>playing</act>
</activities>
<activities>
<refid>2</refid>
<act>running</act>
</activities>
<activities>
<refid>2</refid>
<act>swimming</act>
</activities>
<Date>2013-09-17T18:10:01.3452408+05:30</Date>
</member>
</root>
我在下面尝试过,但我需要通过循环使用数据表选择语句来执行此操作以进行 refid。谁能帮我解决这个问题。
XDocument doc = new XDocument(new XElement("root",
new XElement("member",
new XElement("refid", 1),
new XElement("fname", "Indocin"),
new XElement("lname", "David"),
new XElement("activities", new XElement("refid",1),
new XElement("act","Swimming")),
new XElement("Date", DateTime.Now))));