How can I iterate only through the common nodes between two documents?
Right now, I am able to iterate through all the nodes of my document:
var xmlBody = @"<?xml version="1.0" encoding="UTF-8"?>
<Visit>
<Person>...</Person>
<Name>...</Name>
<Color>...</Color>
</Visit>";
var xdoc = XDocument.Parse(xmlBody);
foreach (XElement child in xdoc.Elements())
{//do stuff}
I'd like to ONLY iterate through the common nodes between xdoc.Elements()
and my nodeList
:
var nodeList = new List<string> { "Name", "LastName", "Color" };
The intersection of the nodeList
and the xdoc
would be just these nodes: Name, Color:
How can I iterate against the intersection, something like this
foreach(XElement child in xdoc.Elements().Intersect(nodeList))