XML file Format:
<pl>
<afs>
<af id="1"></af>
<af id="2"></af>
</afs>
<pss>
<ps>
<a>
<x afid="1"> </x>
<x afid="2"> </x>
</a>
</ps>
<ps>
<a>
<x afid="2"></x>
</a>
</ps>
</pss>
</pl>
For all afs child af nodes, I would like create child x nodes in the parent a node with Attribute values.
I used the following code which is creating only empty elements. I am struck with the comparison, can any one have idea about this. Here is code:
if (this.Xml.Descendants("a").Count() > 0) {
var cs = this.Xml.Descendants("a").ToList();
var cCounts = containers.Select(i => i.Elements("x").Count());
var maxCount = containerCounts.Max();
var afIds = from actionField in this.Xml.Descendants("af").Attributes().ToList(); // Here i get compiler error --
foreach (var c in cs)
{
int count = c.Elements("x").Count();
var xList = c.Descendants("x").ToList();
foreach (var xlst in xList)
{
for (int i = count; i < maxCount; i++)
{
c.Add(new XElement("x", new XAttribute("afid", "1"))); // instead 1 I should have correct id value
}
}
}
}
The result I am trying to get is:
<pl>
<afs>
<af id="1"></af>
<af id="2"></af>
</afs>
<pss>
<ps>
<a>
<x afid="1"> </x>
<x afid="2"> </x>
</a>
</ps>
<ps>
<a>
<x afid="1"></x>
<x afid="2"></x>
</a>
</ps>
</pss>
</pl>