How to lookup, replace and add values to an existing XML file?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
Ive the following XML.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; pre <span style="color:Red; lang<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; x-xml<span style="color:Black; "<span style="color:Blue; ><span style="color:Blue; <<span style="color:#A31515; Root<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; B <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 00000000000<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; C<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; D<span style="color:Blue; >Item1<span style="color:Blue; </<span style="color:#A31515; D<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; E<span style="color:Blue; ><span style="color:Blue; </<span style="color:#A31515; E<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; C<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; C<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; D<span style="color:Blue; >Item2<span style="color:Blue; </<span style="color:#A31515; D<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; E<span style="color:Blue; >123<span style="color:Blue; </<span style="color:#A31515; E<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; C<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; B<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; B <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 00000000000<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; C<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; D<span style="color:Blue; >Item1<span style="color:Blue; </<span style="color:#A31515; D<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; E<span style="color:Blue; ><span style="color:Blue; </<span style="color:#A31515; E<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; C<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; C<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; D<span style="color:Blue; >Item2<span style="color:Blue; </<span style="color:#A31515; D<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; E<span style="color:Blue; >456<span style="color:Blue; </<span style="color:#A31515; E<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; C<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; B<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; B <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 00000000000<span style="color:Black; "<span style="color:Blue; >
...
<span style="color:Blue; </<span style="color:#A31515; B<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Root<span style="color:Blue; >
[/code]
[/code]
Both <B> and <C> occurance > 1, all values of <E> are unique.
How to lookup value in <E>? e.g. <B><C><E>123</E>, then replace value of that <B key="00000000 to "New Value 1" and add <C><D>Item1</D><E>New value 2</E>?
i.e. new XML is,
<pre><B key="New value 1
<C>
<D>Item1</D>
<E>New value 2</E>
</C>
<C>
<D>Item2</D>
<E>123</E>
</C>
</B>
[/code]
Also, should I use XML de/Serializer? or if is there a better option?
Any sample code is greatly appreicated.

View the full article
 
Back
Top