I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first.
Main settings file:
<?xml version="1.0"?>
<preset>
<var id="9" opt="0" val="6666666"/>
<var id="9" opt="1" val="10000000"/>
<var id="9" opt="2" val="10000000"/>
<var id="9" opt="3" val="10000000"/>
<var id="9" opt="4" val="0"/>
<var id="10" opt="0" val="4"/>
<var id="11" opt="0" val="0"/>
<var id="15" opt="0" val="75"/>
<var id="22" opt="0" val="0,0,127,516" type="rect(l,t,r,b)"/>
<var id="23" opt="0" val="27,18,92,66" type="rect(l,t,r,b)"/>
<var id="24" opt="0" val="320"/>
... Skip 300 lines ...
</preset>
And here is an example of the changes:
<?xml version="1.0"?>
<preset>
<var id="15" opt="0" val="425"/>
<var id="22" opt="0" val="0,0,127,776" type="rect(l,t,r,b)"/>
<var id="26" opt="0" val="147"/>
<var id="27" opt="0" val="147"/>
<var id="109" opt="1" val="7"/>
<var id="126" opt="0" val="6,85,85,59" type="crv(t,m,b,vm)"/>
<var id="157" opt="0" val="1"/>
... Skip 10 lines ...
</preset>
Each variable has an ID and an Optimization that ID applies to. Basically, I'm looking to replace the lines where the id="#"
and opt="#"
are the same with the version from the "change" file. In the example above, the value for id="15" opt="0"
would change from 75 to 425.
Would there be any clean way in doing this in C#? At first thought, reading as text and stepping through the changes using a find-replace type of method seems the cleanest. An approach handling this as an XmlDocument
seems like much more work.