Iteration over an XDocument based on some existing elements and conditions
There are several ways how you can process an XML using Linq2XML.
As I can understand you want to process only those XML files that are matching a given format. You can check this with XML native tools, like XSD or DTD schema definitions and validation or manually via XLinq.
If you want to check that with XLinq I would suggest to use the following methods:  Descendants, Elements and Attributes. Each returns those items where the predicate is met. If there is no match, then it will return an empty collection.
If you combine this logic with the Any extension method then you can turn your query operators into existence operators. If the queried collection's length is zero then it returns false otherwise true.

I would suggest to break your logic into two sub-functions:

Check whether or not the given xml meets the desired format
Process only that xml, which satisfies the preconditions


EDIT: To reflect new requirements
Check the presence of the Group element and act based on its existence:
var xml = &quot;&lt;Project&gt;&lt;Group&gt;&lt;Content Include = \&quot;buildings\&quot; /&gt;&lt;/Group&gt;&lt;/Project&gt;&quot;;
var xDocument = XDocument.Parse(xml);
var project = xDocument.Root;
var isGroupExist = project.Elements(&quot;Group&quot;).Any();
if (!isGroupExist)
{
    var group = new XElement(&quot;Group&quot;) { ... };
    project.AddAfterSelf(group);
}
//Process it