C# xml XDocument
string result = string.Empty;
XElement root1 = new XElement("root");
for (int i = 0; i < 2; i++)
{
XElement item1 = new XElement("item",
new XElement("key", "test"),
new XElement("name", "aaa")
);
root1.Add(item1);
}
result = root1.ToString();
output:
<root>
<item>
<key>test</key>
<name>aaa</name>
</item>
<item>
<key>test</key>
<name>aaa</name>
</item>
</root>
標籤: C#