473,799 Members | 2,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3384
oops
Not </td</tthis was typo ;)

Meelis
"Meelis Lilbok" <me***********@ deltmar.eewrote in message
news:uv******** ******@TK2MSFTN GP02.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.Document Element.Transfo rm...

Rick

"Meelis Lilbok" <me***********@ deltmar.eewrote in message
news:uv******** ******@TK2MSFTN GP02.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**@LakeValle ySeed.comwrote in message
news:%2******** ********@TK2MSF TNGP04.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.Document Element.Transfo rm...

Rick

"Meelis Lilbok" <me***********@ deltmar.eewrote in message
news:uv******** ******@TK2MSFTN GP02.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******** ******@TK2MSFTN GP02.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(Estoni an)
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******** ******@TK2MSFTN GP02.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(Estoni an)
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:\tem p\xml1.xml")
Dim xml2 : Set xml2 = LoadDOM("g:\tem p\xml2.xml")
Dim oNode

Set oNode = xml2.documentEl ement.lastChild
Set oNode = xml1.selectSing leNode("//t[@id='" & oNode.getAttrib ute("id") &
"']")

For Each oNode in oNode.selectNod es("following-sibling::t")
xml2.documentEl ement.appendChi ld(oNode.cloneN ode(true))
Next

xml2.save "g:\temp\xml2.x ml"

Function LoadDOM(sFile)

Set LoadDOM = CreateObject("M SXML2.DOMDocume nt.3.0")
LoadDOM.async = False
LoadDOM.setProp erty "SelectionLangu age", "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["myNonexistentK ey"] = 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(strin g.format(" <t id=""{0}"">{1} </t>" & vbLf,
thing.key.tostr ing, thing.value.tos tring))
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
2050
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 type 10 reason code 2. Because we have the german version i translate the reason text as meaningful as possible: The row was updated at 'publisher.database' but could not be updated
1
4118
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 the Saxon xml parser. Can someone please help me to get this to work? The two xml input files follow, as well as my attempt to write the merge xsl (merge_on_date_time.xsl): lrv_1_transaction_cid_1.xml: ---------------------------- <?xml...
8
9527
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 each person for whom a mail merge letter is desired. The query reads address info from the table for each record where is true.
0
1319
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 are included in the merge modules, because it remove the files necossary to for development. How can i prevent the uninstall from removing that files. I know that normal project files i can set the permanent property to true and will not be...
8
1873
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? If it is possible what would be the best technology to implement the solution (XMLDom, XSLT...)? How hard would the solution be?
1
4296
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 target location ('\8.0.50727.42.cat') WARNING: Two or more objects have the same target location ('\8.0.50727.42.cat')
0
2277
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. My requirement is to automatically synchronize a folder on the device (on storage card) with a folder on the computer. I looked at the OpenNETCF.Communications library used the CopyFileFromDevice and CopyFileToDevice functions in it. But I didn't...
4
7224
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 compile error stating that it cannot find: "C:\Program Files\Common Files\Merge Modules\Crystal_regwiz2003.msm" I am not sure where to get this file or even if it is appropriate (i.e., should there be a newer version for Visual Studio 2005).
1
14890
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: "Microsoft.VC90.CRT" "9.0.21022.8" "x86". I created an MSI package with the following merge modules: "Program Files\Common Files\Merge Modules\Microsoft_VC90_CRT_x86.msm" and "policy_9_0_Microsoft_VC90_CRT_x86.msm".
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10491
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10031
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.