I am using XML reader to search through an xml configuration file we use. I want to find the values under a certain key and be able to change them or add if they don't exist.
XML Sample
<DBSimulatorConfigurations>
<Configurations>
<DBSimulatorConfiguration>
<Key>Test1</Key>
<Submit>0</Submit>
<Amend>0</Amend>
<Update>0</Update>
<Delete>1</Delete>
<ResponseTimeInSeconds>100</ResponseTimeInSeconds>
</DBSimulatorConfiguration>
<DBSimulatorConfiguration>
<Key>Test2</Key>
<Submit>0</Submit>
<AutoUpdate>0</AutoUpdate>
<Amend>0</Amend>
<Update>0</Update>
<Delete>1</Delete>
<ResponseTimeInSeconds>100</ResponseTimeInSeconds>
</DBSimulatorConfiguration>
<DBSimulatorConfiguration>
</Configurations>
</DBSimulatorConfigurations>
Code so far... commented out bit doesn't find the value within 'Test1'
XmlReader reader = XmlReader.Create("C:\\<path>\\DBConfigs.xml");
while(reader.Read())
{
if (reader.ReadToDescendant("Key"))
{
reader.Read();
if (reader.Value == "Test1")
{
Console.WriteLine("Found_1 {0}", reader.Value);
// Doesn't work :(
// reader.Read();
//if (reader.ReadToDescendant("Submit")) {
// Console.WriteLine("Value for Submit is {0}", reader.Value);
//}
}
if (reader.Value == "Test2")
{
Console.WriteLine("Found_2 {0}", reader.Value);
}
reader.Read(); //this moves reader to next node which is text
if (reader.ReadToDescendant("Full.2")) {
Console.WriteLine("Found {0}", reader.Value);
}
}
But what I want to do then is find and change the value for 'Submit' or 'Amend' etc or if there is no entry 'Submit' then i'll add one.
But first i'd like to be able to find and change the values for Test1.