Structuring XDocument to properly format Tags

Gloriaellis

New Member
I have an \[code\]XDocument\[/code\] being created that gets populated with a set of data.The output looks like so:\[code\] <Results> <RuleResult> <Title> RuleTitle </Title> </RuleResult> <RuleResult> <Title> Rule2Title </Title> </RuleResult> </Results>\[/code\]now how I have this formulated in C# is as follows:\[code\] 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())); } }\[/code\]To my understanding, this creates \[code\]"Results"\[/code\] as the root level node.My question is, if I want to set it up so that encapsulating all of the above is \[code\]<AnalysisSets>\[/code\] so it would be:\[code\] <AnalaysisSets> <AnalysisSet ProviderName="ProductNameHere"> <Results> <....xml data..../> </Results> </AnalysisSet> </AnalysisSets>\[/code\]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.
 
Back
Top