I’m trying to write a piece of code which receives a string, uses the data in this string to make changes to another string then saves the other string
I would prefer to do this using linq as I’m somewhat familiar with it, although that’s not to say that I’m completely close minded.
Anyway, the string being received is in a form like
"<?xml version=\"1.0\" encoding=\"utf-8\"?><Root><Value><Code>AAA</Code><Description>First description</Description><Bool>Y</Bool></Value><Value><Code>BBB</Code><Description>Second description</Description><Bool>Y</Bool></Value><Value><Code>CCC</Code><Description>Third description</Description><Bool>N</Bool></Value></Root>";
or with proper formatting
"<?xml version=\"1.0\" encoding=\"utf-8\"?>
<Root>
<Value>
<Code>AAA</Code>
<Description>First description</Description>
<Bool>Y</Bool>
</Value>
<Value>
<Code>BBB</Code>
<Description>Second description</Description>
<Bool>Y</Bool>
</Value>
<Value>
<Code>CCC</Code>
<Description>Third description</Description>
<Bool>N</Bool>
</Value>
</Root>"
and, for example. the other value is like
"<?xml version=\"1.0\" encoding=\"utf-8\"?>
<Root>
<Value>
<Code>111</Code>
<Description>111 description</Description>
<Bool>Y</Bool>
</Value>
<Value>
<Code>AAA</Code>
<Description>First description</Description>
<Bool>Y</Bool>
</Value>
<Value>
<Code>222</Code>
<Description>222 description</Description>
<Bool>Y</Bool>
</Value>
<Value>
<Code>BBB</Code>
<Description>Second description</Description>
<Bool>Y</Bool>
</Value>
<Value>
<Code>333</Code>
<Description>333 description</Description>
<Bool>Y</Bool>
</Value>
<Value>
<Code>CCC</Code>
<Description>Third description</Description>
<Bool>Y</Bool>
</Value>
</Root>"
so of the same form but with more values and with all Bools set to Y. All I want to do is to find all the codes with a bool set to N and set those Bools on the new XML to N.
so the result of combining both of these would be the new xml but the Value with code CCC would have the Bool set as N. so:
"<?xml version=\"1.0\" encoding=\"utf-8\"?>
<Root>
<Value>
<Code>111</Code>
<Description>111 description</Description>
<Bool>Y</Bool>
</Value>
<Value>
<Code>AAA</Code>
<Description>First description</Description>
<Bool>Y</Bool>
</Value>
<Value>
<Code>222</Code>
<Description>222 description</Description>
<Bool>Y</Bool>
</Value>
<Value>
<Code>BBB</Code>
<Description>Second description</Description>
<Bool>Y</Bool>
</Value>
<Value>
<Code>333</Code>
<Description>333 description</Description>
<Bool>Y</Bool>
</Value>
<Value>
<Code>CCC</Code>
<Description>Third description</Description>
<Bool>N</Bool>
</Value>
</Root>"
To me it seems as though there should be an incredibly easy way to do this using Linq to XML but I’ve been working at it for a while now and my inexperience with XML seems to be showing as I’m having quite a bit of trouble with this.
Any help would be much appreciated.
Thanks
Something like that?