Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Merge/Synchronize XML Files

From: "Andrew Morton" <akm@--------.--.--.------->
To: NULL
Date: 11/3/2006 3:20:00 PM

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 




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