我的数据集中有 2 个表。
我需要将我的 XML 构造为:
<MyRoot>
<Settings>
<Param1>value1</Param1>
<Param2>value2</Param2>
<Param3>value3</Param3>
</Settings>
<Books>
<Book>
<BookId>1000</BookId>
<BookName>Book1</BookName>
</Book>
<Book>
<BookId>2000</BookId>
<BookName>Book2</BookName>
</Book>
</Books>
</MyRoot>
但是当我使用 datSet.WriteXML(); 我得到的 XML 为:
<MyRoot>
<Settings>
<Param1>value1</Param1>
<Param2>value2</Param2>
<Param3>value3</Param3>
</Settings>
<Book>
<BookId>1000</BookId>
<BookName>Book1</BookName>
</Book>
<Book>
<BookId>2000</BookId>
<BookName>Book2</BookName>
</Book>
</MyRoot>
因此,我无法将单独的数据集名称作为“Books”添加到第二个表(dataSet.Tables[1])。有什么办法可以做到吗?
我尝试了以下代码:
dataSet = GetList();
dataSet.DataSetName = "MyRoot";
dataSet.Tables[0].TableName = "Settings";
dataSet.Tables[1].TableName = "Books";
StringWriter swriter = new StringWriter();
dataSet.WriteXml(swriter);
string dsResult = swriter.ToString();
谢谢。