473,327 Members | 2,074 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,327 software developers and data experts.

Merging XML files with identical schemas in C# ? How to?

Hi!
I also asked this question in C# group with no results:

I have 2 datasets loaded with data from two xml files having the same
schema. The files contain data from yesterday and today. I'd like to merge
both datasets in such a way that the resulting dataset should have all the
today's data overriding yestrerday's data. CATCH: the today's
dataset contains only the daily changes (DELTA) and merging should not
remove all
unchanged records from yesterday.

What's the most efficient way of doing so ? I thought ds.Merge() method
would work for me, but I can't make it work. It seems that I can append two
datasets but not merge
ds1.Merge(ds2,false)

Many Thanks in Advance,

Nov 12 '05 #1
3 10995
Hi Mike

I'm pretty sure that the behaviour you are after is the default behaviour.
You need to have set up the primary keys on the table so that updated rows
can be identified. The only thing I've found that isn't mapped through is
deletions - but new and changed data is merged.

Is that not what you are finding?

Nigel

"Mike" wrote:
Hi!
I also asked this question in C# group with no results:

I have 2 datasets loaded with data from two xml files having the same
schema. The files contain data from yesterday and today. I'd like to merge
both datasets in such a way that the resulting dataset should have all the
today's data overriding yestrerday's data. CATCH: the today's
dataset contains only the daily changes (DELTA) and merging should not
remove all
unchanged records from yesterday.

What's the most efficient way of doing so ? I thought ds.Merge() method
would work for me, but I can't make it work. It seems that I can append two
datasets but not merge
ds1.Merge(ds2,false)

Many Thanks in Advance,

Nov 12 '05 #2
Hi! Thank you for taking a look. I am populating my datasets from XML files.
I have no clue how to set up the primary keys on the table. Perhaps you can
point me in the right direction ? Without primary keys set, I saw 2 datasets
just appending all data to each other.

Many Thanks

--Mike

"Nigel Armstrong" wrote:
Hi Mike

I'm pretty sure that the behaviour you are after is the default behaviour.
You need to have set up the primary keys on the table so that updated rows
can be identified. The only thing I've found that isn't mapped through is
deletions - but new and changed data is merged.

Is that not what you are finding?

Nigel

"Mike" wrote:
Hi!
I also asked this question in C# group with no results:

I have 2 datasets loaded with data from two xml files having the same
schema. The files contain data from yesterday and today. I'd like to merge
both datasets in such a way that the resulting dataset should have all the
today's data overriding yestrerday's data. CATCH: the today's
dataset contains only the daily changes (DELTA) and merging should not
remove all
unchanged records from yesterday.

What's the most efficient way of doing so ? I thought ds.Merge() method
would work for me, but I can't make it work. It seems that I can append two
datasets but not merge
ds1.Merge(ds2,false)

Many Thanks in Advance,

Nov 12 '05 #3
Hi Mike

Files follow. We have Stuff.xsd, the schema file. Run this through the xsd
utility using the /dataset option to generate the DataSet classes.

Stuff.xsd
<?xml version="1.0" standalone="yes"?>
<xs:schema id="Stuff" targetNamespace="http://www.tempuri.org/Stuff.xsd"
xmlns:mstns="http://www.tempuri.org/Stuff.xsd"
xmlns="http://www.tempuri.org/Stuff.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="Stuff" msdata:IsDataSet="true" msdata:Locale="en-GB">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="id" msdata:ReadOnly="true"
msdata:AutoIncrement="true" type="xs:int" />
<xs:element name="Food" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:Table" />
<xs:field xpath="mstns:id" />
</xs:unique>
</xs:element>
</xs:schema>

Two xml files, base.xml the data as it is now and delta.xml, the changes.

base.xml
<?xml version="1.0" standalone="yes"?>
<Stuff xmlns="http://www.tempuri.org/Stuff.xsd">
<Table>
<id>1</id>
<Food>Apple</Food>
</Table>
<Table>
<id>2</id>
<Food>Banana</Food>
</Table>
<Table>
<id>3</id>
<Food>Carrot</Food>
</Table>
<Table>
<id>4</id>
<Food>Doughnut</Food>
</Table>
<Table>
<id>5</id>
<Food>Egg</Food>
</Table>
</Stuff>

delta.xml
<?xml version="1.0" standalone="yes"?>
<Stuff xmlns="http://www.tempuri.org/Stuff.xsd">
<Table>
<id>2</id>
<Food>Bananas</Food>
</Table>
<Table>
<id>5</id>
<Food>Eggs</Food>
</Table>
<Table>
<id>7</id>
<Food>Grits</Food>
</Table>
<Table>
<id>8</id>
<Food>Hash Browns</Food>
</Table>
</Stuff>

Finally some code. Load up base.xml, then merge it with delta.xml

Stuff s = new Stuff();
s.ReadXml(@"C:\base.xml");
MessageBox.Show(s.GetXml());
Stuff s2 = new Stuff();
s2.ReadXml(@"C:\delta.xml");
MessageBox.Show(s2.GetXml());
s.Merge(s2);
MessageBox.Show(s.GetXml());

This works for me...

HTH

Nigel

Nov 12 '05 #4

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

Similar topics

15
by: Ike | last post by:
Suppose I have a relational database, called "BranchA." I have a second relational database, of identical structure to BranchA, but with different data, and this one is called BranchB. Can I...
1
by: Jeff | last post by:
We're having some trouble with some PDF files sent to our customers, they aren't able to be read because they are "damaged, and cannot be repaired". Looking into this, I think it has to do with...
0
by: Mike | last post by:
Hi! I have 2 datasets loaded with data from two xml files having the same schema. The files contain data from yesterday and today. I'd like to merge both datasets in such a way that the resulting...
0
by: Eric Mamet | last post by:
Everytime I try to look at a web user control in design mode, Visual Studio prompts me for checking out the file from Visual Source Safe. Apparently, it just shuffles around the first three lines...
2
by: Thanya Teutschbeim | last post by:
I'm trying to use DataSet.Merge, but it works like an Append, and I don't want this. I want to update dataset data. I have two files with same fields and the same xml schema. For example: File...
3
by: Sanjib Biswas | last post by:
Hi All, I am looking for XML merging for the following scenarios. I want to load both the input files and show in the tree viewer and highlight the differences. Now its up to the user to select...
1
by: samn | last post by:
I wrote the following script in order to traverse an HTML table and merge the cells that have the same value across multiple rows. For some reason, however, it works for the first, third, and...
3
by: Ralph Smith | last post by:
I have two identical databases on two different servers and I need to add the data in tables from one server to the tables in the other server. Is there a way to do that in mysql? thanks, Ralph
1
by: Big X | last post by:
I have already achieved this in access and was trying with straight SQL earlier I would just like to know what I'm doing wrong in sql or what syntax I'm missing. I have three tables with identical...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.