473,385 Members | 1,742 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,385 software developers and data experts.

Merge/Synchronize XML Files

Hi is for synchronizing two xml files any fast solution?

Lets say i have 2 xml files 1.xml and 2.xml

1.xml contianes

<test>
<t id="1">Hello</t>
<t id="2">World</t>
<t id="3">Good bye!</td>
</test>

2.xml containes
<test>
<t id="1">Hello</t>
<t id="2">World</t>
</test>

After synchronizing 2.xml must look likt this
<test>
<t id="1">Hello</t>
<t id="2">World</t>
<t id="3">Good bye!</td>
</test>

At the moment i use
For Each
Next
and this is too slow, if file containes about 1000 <tnodes

Regards;
Meelis

Nov 3 '06 #1
7 3362
oops
Not </td</tthis was typo ;)

Meelis
"Meelis Lilbok" <me***********@deltmar.eewrote in message
news:uv**************@TK2MSFTNGP02.phx.gbl...
Hi is for synchronizing two xml files any fast solution?

Lets say i have 2 xml files 1.xml and 2.xml

1.xml contianes

<test>
<t id="1">Hello</t>
<t id="2">World</t>
<t id="3">Good bye!</td>
</test>

2.xml containes
<test>
<t id="1">Hello</t>
<t id="2">World</t>
</test>

After synchronizing 2.xml must look likt this
<test>
<t id="1">Hello</t>
<t id="2">World</t>
<t id="3">Good bye!</td>
</test>

At the moment i use
For Each
Next
and this is too slow, if file containes about 1000 <tnodes

Regards;
Meelis

Nov 3 '06 #2
Why don't you try writing an XSLT transformation that combines all the
nodes in <testand then eliminates the duplicates? I think you could either
combine the two xml documents prior to the transform, or perhaps by
importing them from within the XSLT.

You can then do an xmlDoc.DocumentElement.Transform...

Rick

"Meelis Lilbok" <me***********@deltmar.eewrote in message
news:uv**************@TK2MSFTNGP02.phx.gbl...
Hi is for synchronizing two xml files any fast solution?

Lets say i have 2 xml files 1.xml and 2.xml

1.xml contianes

<test>
<t id="1">Hello</t>
<t id="2">World</t>
<t id="3">Good bye!</td>
</test>

2.xml containes
<test>
<t id="1">Hello</t>
<t id="2">World</t>
</test>

After synchronizing 2.xml must look likt this
<test>
<t id="1">Hello</t>
<t id="2">World</t>
<t id="3">Good bye!</td>
</test>

At the moment i use
For Each
Next
and this is too slow, if file containes about 1000 <tnodes

Regards;
Meelis

Nov 3 '06 #3
sry im not very familyar with xslt
where should i begin? any samples?

Meelis
"Rick" <Ri**@LakeValleySeed.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Why don't you try writing an XSLT transformation that combines all the
nodes in <testand then eliminates the duplicates? I think you could
either combine the two xml documents prior to the transform, or perhaps by
importing them from within the XSLT.

You can then do an xmlDoc.DocumentElement.Transform...

Rick

"Meelis Lilbok" <me***********@deltmar.eewrote in message
news:uv**************@TK2MSFTNGP02.phx.gbl...
>Hi is for synchronizing two xml files any fast solution?

Lets say i have 2 xml files 1.xml and 2.xml

1.xml contianes

<test>
<t id="1">Hello</t>
<t id="2">World</t>
<t id="3">Good bye!</td>
</test>

2.xml containes
<test>
<t id="1">Hello</t>
<t id="2">World</t>
</test>

After synchronizing 2.xml must look likt this
<test>
<t id="1">Hello</t>
<t id="2">World</t>
<t id="3">Good bye!</td>
</test>

At the moment i use
For Each
Next
and this is too slow, if file containes about 1000 <tnodes

Regards;
Meelis


Nov 3 '06 #4

"Meelis Lilbok" <me***********@deltmar.eewrote in message
news:uv**************@TK2MSFTNGP02.phx.gbl...
Hi is for synchronizing two xml files any fast solution?

Lets say i have 2 xml files 1.xml and 2.xml

1.xml contianes

<test>
<t id="1">Hello</t>
<t id="2">World</t>
<t id="3">Good bye!</td>
</test>

2.xml containes
<test>
<t id="1">Hello</t>
<t id="2">World</t>
</test>

After synchronizing 2.xml must look likt this
<test>
<t id="1">Hello</t>
<t id="2">World</t>
<t id="3">Good bye!</td>
</test>

At the moment i use
For Each
Next
and this is too slow, if file containes about 1000 <tnodes

Regards;
Meelis
I suspect that a loop using .nextNode on either the input, target or both
per iteration will suit your needs Although XSL may still outperform a
script based language doing this even 1000 nodes shouldn't take an excessive
amount of time.

Your example doesn't show why you simply don't replace 2.xml with 1.xml.
More detail show the wider set of cases are needed to arrive at an
apporpriate solution.

If id="1" were missing from 1.XML should it be deleted from 2.xml?
If id="2" in 2.xml contained the word 'kosmos' should it contain 'world'
after the merge because it was replaced by id="2" from 1.xml?
In the real world is t a complex element if so do you intend to merge the
contents of ts of the same id from each xml file or simply replace the t in
2.xml with the one in 1.xml?


Nov 3 '06 #5
If id="1" were missing from 1.XML should it be deleted from 2.xml?
If id="2" in 2.xml contained the word 'kosmos' should it contain 'world'
after the merge because it was replaced by id="2" from 1.xml?
In the real world is t a complex element if so do you intend to merge the
contents of ts of the same id from each xml file or simply replace the t
in
2.xml with the one in 1.xml?
Yes i cant simly replace beacuse in one file node with id="2" can have
"Hello"
in second file id="2" may have "Hallo"

I try to explain little bit more :=

file 1.xml is a "template" file, containing strings/texts in native
language(Estonian)
With my application users can translate strings to they own language.
When now user launches translator application

1) template is loaded from server
2) application checks if template file contains new id's(nodes) and adds
those nodes to user file.
[template.xml]
<test>
<t id="1">Tere</t>
<t id="2">Maailm</t>
<t id="3">Head aega!</t>
</test>

[user.xml]
<test>
<t id="1">Hallo</t>
<t id="2">World</t>
</test>
After synchronizing user.xml must look like this
<test>
<t id="1">Hello</t>
<t id="2">World</t>
<t id="3">Head aega!</t>
</test>


Meelis


Nov 3 '06 #6

"Meelis Lilbok" <me***********@deltmar.eewrote in message
news:eX**************@TK2MSFTNGP02.phx.gbl...
If id="1" were missing from 1.XML should it be deleted from 2.xml?
If id="2" in 2.xml contained the word 'kosmos' should it contain 'world'
after the merge because it was replaced by id="2" from 1.xml?
In the real world is t a complex element if so do you intend to merge
the
contents of ts of the same id from each xml file or simply replace the t
in
2.xml with the one in 1.xml?

Yes i cant simly replace beacuse in one file node with id="2" can have
"Hello"
in second file id="2" may have "Hallo"

I try to explain little bit more :=

file 1.xml is a "template" file, containing strings/texts in native
language(Estonian)
With my application users can translate strings to they own language.
When now user launches translator application

1) template is loaded from server
2) application checks if template file contains new id's(nodes) and adds
those nodes to user file.
[template.xml]
<test>
<t id="1">Tere</t>
<t id="2">Maailm</t>
<t id="3">Head aega!</t>
</test>

[user.xml]
<test>
<t id="1">Hallo</t>
<t id="2">World</t>
</test>
After synchronizing user.xml must look like this
<test>
<t id="1">Hello</t>
<t id="2">World</t>
<t id="3">Head aega!</t>
</test>
So if I've understood it correctly all you really need is add new nodes that
have appeared at the end of 1.xml to the end of 2.xml? Sounds a little
simplistic so I probably haven't understood your requirement but if it is
then:-
Option Explicit

Dim xml1 : Set xml1 = LoadDOM("g:\temp\xml1.xml")
Dim xml2 : Set xml2 = LoadDOM("g:\temp\xml2.xml")
Dim oNode

Set oNode = xml2.documentElement.lastChild
Set oNode = xml1.selectSingleNode("//t[@id='" & oNode.getAttribute("id") &
"']")

For Each oNode in oNode.selectNodes("following-sibling::t")
xml2.documentElement.appendChild(oNode.cloneNode(t rue))
Next

xml2.save "g:\temp\xml2.xml"

Function LoadDOM(sFile)

Set LoadDOM = CreateObject("MSXML2.DOMDocument.3.0")
LoadDOM.async = False
LoadDOM.setProperty "SelectionLanguage", "XPath"
LoadDOM.load sFile

End Function
This for eaches only the new nodes the end of xml1 which are not already in
xml2.

>
Meelis


Nov 3 '06 #7
Meelis Lilbok wrote:
Yes i cant simly replace beacuse in one file node with id="2" can have
"Hello"
in second file id="2" may have "Hallo"

I try to explain little bit more :=

[template.xml]
<test>
<t id="1">Tere</t>
<t id="2">Maailm</t>
<t id="3">Head aega!</t>
</test>

[user.xml]
<test>
<t id="1">Hallo</t>
<t id="2">World</t>
</test>
After synchronizing user.xml must look like this
<test>
<t id="1">Hello</t>
I assume you meant to type Hallo...
<t id="2">World</t>
<t id="3">Head aega!</t>
</test>
If you get rid of all the XML noise, you will be left with name-value pairs
(see DictionaryEntry in the help).

"1" "Hallo"
"2" "World"
If you then put the template DictionaryEntry items into a Hashtable (q.v.)
followed by the values extracted from the user.xml file *but taking note of
this from the Hashtable.Add method help*:

"The Item property can also be used to add new elements by setting the value
of a key that does not exist in the Hashtable. For example:
myCollection["myNonexistentKey"] = myValue. However, if the specified key
already exists in the Hashtable, setting the Item property overwrites the
old value. In contrast, the Add method does not modify existing elements."

then you will have a hashtable containing the merged data.
You can then take the data from the hashtable, add back in all the XML cr^W
stuff as you Append it to a StringBuilder, then write back to disk. The
whole operation should take about as long as it takes to double-click a
mouse button.

' not checked, but this is how you'd re-build the XML
dim sb as new StringBuilder("<test>" & vbLF)
for each thing as DictionaryEntry in yourHashtable
sb.Append(string.format(" <t id=""{0}"">{1}</t>" & vbLf,
thing.key.tostring, thing.value.tostring))
next
sb.Append("</test>")
' now write the file

Any use?

Andrew
Nov 3 '06 #8

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

Similar topics

0
by: Gert Wurzer | last post by:
Hi! I hope anyone can help me with this very important problem! Since configurig one subscriber in our merge replication scenario to a subscribing publisher we get a lot of merge conflicts...
1
by: Luke Airig | last post by:
I have two xml files that I need to merge on their common field (date_time). The merged output file needs to have the date_time field and all fields from both of the two input files. I am using...
8
by: Squirrel | last post by:
Hi everyone, I've created a mail merge Word doc. (using Office XP) , the data source is an Access query. Functionality I'm attempting to set up is: User sets a boolean field to true for...
0
by: Shrage H. Smilowitz | last post by:
Hi, I have created a setup project in vs.net, i have included several merge modules, but when i test the installation on my development machine i dont want the uninstall to remove the files that...
8
by: ilikesluts | last post by:
Hi Group, I'm new to XML, here is my question: Would it be possible to write an algorithm that takes in two XML documents with the only condition being that they have the same root element? ...
1
by: mjobbe | last post by:
I have an installer that requires three merge modules (ATL, CRT, and MFC), and after adding them in, I get the following warnings when I build the MSI: WARNING: Two or more objects have the same...
0
by: krupa.p | last post by:
Hi All, I am trying to write a C# .Net desktop application that synchronizes files/folders on the PC with those on a Windows CE device, when the device is connected to the PC via ActiveSync. ...
4
by: Tom Jones | last post by:
I have an application that was originally built using Visual Studio 2003 that I upgraded to Visual Studio 2005. When I attempt to build the *.msi file in the deployment project, I am getting a...
1
by: cristalink | last post by:
Hi, I have MS Visual Studio 2008 both Pro and Dev Team Edition SP1 installed. I've compiled a managed C++ .DLL which automatically had a manifest embedded, with the following dependency:...
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...
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...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.