473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Modify an XML File with a DataSet and Child Relations

Hello,

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
yet:
DataTable tbSelections = dsConfig.Tables["selector"];
DataTable tbItems = dsConfig.Tables["item"];

foreach (DataRow row in tbSelections.Rows)
{
if (cb_selector.SelectedItem.ToString() ==
row["name"].ToString())
{
string[] lines = tb_selectoritem.Lines;
DataRow[] rowstemp =
row.GetChildRows("selector_item");
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
if(lines.Length!=rowstemp.Length)
{
rows=new DataRow[lines.Length];
}
else
{
rows=new DataRow[rowstemp.Length];
}
if (lines.Length < rowstemp.Length)
Array.Copy(rowstemp, rows, lines.Length);
else
Array.Copy(rowstemp,rows,rowstemp.Length);

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

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

DataRow childrow = rows[i];
childrow["item_Text"] = lines[i];
tbItems.Rows.Add(childrow);
}
With this code the output looks something like this:

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

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

TIA,
Patrick

May 4 '07 #1
0 1242

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: davis | last post by:
Hello, I am working in .Net C# and have an xml file similar to the one below. I have tried using a DataSet but get the error "The same table (Gid) cannot be the child table in two nested...
1
by: Fleckman | last post by:
I have a situation where I need to add rows to tables with a Parent-Child relationship which presents a constraints violation when I reject the changes. Here is the scenario: I add a row to a...
2
by: Kenny | last post by:
Hello all, I've made a dataset by using the xsd tool in C#. In the xsd schema, there are a few tables, each has its own primary key. And, I've made relation between them. After all things are...
9
by: Mr Newbie | last post by:
HI People, Thanks to all who helped me earlier on the subject of @@IDentity. However, I seem to have hit another snagette! My DataSet contains two tables from the SQL Server. lets say Master...
11
by: Kay | last post by:
Hi all, I have populated a dataset with several tables, say - Roster, Agent and few more . The dataset is used to populated a listview with some shift info.. I think I'm sucessfully created a...
2
by: Joe | last post by:
Hi I have a dataset with 3 tables and 2 relations Is there a way to when I am at 1 row to tell if there is a relation on that row ??? I have the code hardcoded but try to make it work if the #...
2
by: randy1200 | last post by:
My hope is that somebody has a thought on this, or can point to toward an article that's useful. I have the following: DataSet ds = new DataSet(); ds.ReadXml("MyData.xml"); Each MainTable...
3
by: Eric | last post by:
Help! I created a XML schema with a Visual Studio tools. I'm filling a dataset with a DataAdapter. Before I use the "WriteXml" method to write the data to a xml file, I want to map the XSD file I...
0
by: sparty1022 | last post by:
Read many of the posting but still doen't understand the process. I have a dataset with child records. I have a specific XML "Account.XSD" format that I need to write this out to. How do I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.