I’ve got 2 XElements. Each containing multiple children Elements
eg
Xml1:
<Addresses>
<Address>
<Line1>1 Street</Line1>
<Postcode>PL1 5RT</Postcode>
</Address>
<Line1>57 New Street</Line1>
<Postcode>PL1 5RT</Postcode>
</Address>
<Address>
<Line1>2 Street</Line1>
<Postcode>PL1 5RT</Postcode>
</Address>
</Addresses>
Xml2:
<Addresses>
<Address>
<Line1>1 Street</Line1>
<Postcode>PL1 5RT</Postcode>
</Address>
<Address>
<Line1>2 Street</Line1>
<Postcode>PL1 5RT</Postcode>
</Address>
</Addresses>
I’m trying to put together a linq query that will filter out the address elements that are in Xml but not in Xml2 (in the above case it would be address “57 New Street”)
Currently my code looks like this:
var diffAddress = from address1 in Xml1.Elements()
from address2 in Xml2.Elements()
where (string)address1.Element("Line1") != (string)address2.Element("Line1") ||
where (string)address1.Element("Postcode") != (string)address2.Element("Postcode")
select address1;
However its returning all of the values in Xml1
Am I right in thinking that i can do this via a single query or would i have to get the results from both and then iterate through them to get the Addresses in Xml1 that aren’t in Xml2??
Any help would be greatly appreciated 🙂
Thanks for the info Paul!
Below is the code which fits my solution using the “Except” operator