I would like to complete the below XML so all Parent elements have all 3 child elements.
<Parent>
<Child1></Child1>
<Child2></Child2>
<Child3></Child3>
</Parent>
<Parent>
<Child3></Child3>
</Parent>
<Parent>
<Child1></Child1>
<Child3></Child3>
</Parent>
So i got the below code
var elementsToChange = inputDoc.Descendants(CommonConstant.Parent);
foreach (var element in elementsToChange)
{
if (element.Element(CommonConstant.Child1) == null)
{
//add child1 at 1
}
if (element.Element(CommonConstant.Child2) == null)
{
//add child2 at 2
}
}
But i can’t find an Insert() or AddAT() on element. (and since i dont know what childs exist, using add afetr or before self are hard to use.)
Is there a way of adding a child at a certain location?
Try this: