Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Merge/Synchronize XML Files

From: "Anthony Jones" <Ant@------------.--->
To: NULL
Date: 11/3/2006 2:50:00 PM


"Meelis Lilbok" <meelis.lilbok@d...> wrote in message
news:eXkxDu0$GHA.4292@T......
> > 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(true))
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
>
>
>
>




transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent