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