467,118 Members | 999 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,118 developers. It's quick & easy.

Modify an XML File with a DataSet and Child Relations


I want to modify an existing XML-File based on Input in a Form.
I used a DataSet to load the XML File with the ReadXml method.

I then displayed the relevant entries via the GetChildRows method.

I now want to change/add/delete those ChildRows:

How can I accomplish this?

Here is the code I used to modify the Dataset, but it is not working
DataTable tbSelections = dsConfig.Tables["selector"];
DataTable tbItems = dsConfig.Tables["item"];

foreach (DataRow row in tbSelections.Rows)
if (cb_selector.SelectedItem.ToString() ==
string[] lines = tb_selectoritem.Lines;
DataRow[] rowstemp =
DataRow[] rows;
// check if we more or less entries than before, so that we know we
have to add or delete or just change entries
rows=new DataRow[lines.Length];
rows=new DataRow[rowstemp.Length];
if (lines.Length < rowstemp.Length)
Array.Copy(rowstemp, rows, lines.Length);

// delete the existing childrows, we have to create all of them
for (int i = 0; i < tbItems.Rows.Count; ++i)
DataRow item = tbItems.Rows[i];
if (cb_selector.SelectedIndex ==
i = 0;

// create the entries
for (int i = 0; i < lines.Length; ++i)

DataRow childrow = rows[i];
childrow["item_Text"] = lines[i];
With this code the output looks something like this:

<selector name="foo" />
<item>New Item</item>

But I want to have the new item under "foo".


May 4 '07 #1
  • viewed: 1063

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by davis | last post: by
1 post views Thread by Fleckman | last post: by
2 posts views Thread by Joe | last post: by
2 posts views Thread by randy1200 | last post: by
reply views Thread by sparty1022 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.