I have an XDocument being created that gets populated with a set of data.
The output looks like so:
<Results>
<RuleResult>
<Title> RuleTitle </Title>
</RuleResult>
<RuleResult>
<Title> Rule2Title </Title>
</RuleResult>
</Results>
now how I have this formulated in C# is as follows:
XDocument doc = new XDocument(new XElement("Results"));
foreach (AnalysisSet rules in allAnalysisSets)
{
foreach (var rule in rules.Rules)
{
doc.Root.Add(new XElement(rule.GetRuleState()));
}
}
To my understanding, this creates "Results" as the root level node.
My question is, if I want to set it up so that encapsulating all of the above is <AnalysisSets> so it would be:
<AnalaysisSets>
<AnalysisSet ProviderName="ProductNameHere">
<Results>
<....xml data..../>
</Results>
</AnalysisSet>
</AnalysisSets>
How would I do this? It seems like I would be trying to create a Root element, and then 2 sub root elements? I am not quite sure how to go about accomplishing that, if that is indeed the right track to begin with.
Have you considered just using straight up serialization? Anyway here is my complete mockup.
Edit: I forgot the Results node 🙂