开发者

Saving nested XML in C#

I've go the following XML file...

<A>
  <B>
    <C>ValueX</C>
    <D>ValueY</D>
  </B>
</A>

Which I read into a DataSet to display it in a DataGridView.

DataSet ds = new DataSet();
DataTable t = new DataTable("B");
ds.Tables.Add(t);
t.Columns.Add("C", typeof(string));
t.Columns.Add("D", typeof(string));
// bind to DataGridView
ds.ReadXml(file);

But when I write 开发者_如何学JAVAit back using the follwing command...

ds.WriteXml(file);

the nested structure of the file is destroyed.

<A>
  <C>ValueX</C>
  <D>ValueY</D>
</A>

Any ideas how to preserve the stcuture.


Setting a xsd file and readxml should be sufficient. I think there is no need for the tables and columns.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜