Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8950333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:25:51+00:00 2026-06-15T13:25:51+00:00

I have an XDocument being created that gets populated with a set of data.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:25:52+00:00Added an answer on June 15, 2026 at 1:25 pm

    Have you considered just using straight up serialization? Anyway here is my complete mockup.

    Edit: I forgot the Results node 🙂

    public class Program
    {
        private static void Main(string[] args)
        {
            var allAnalysisSets = new AnalysisSet[] {
                new AnalysisSet(){
                    ProviderName = "productname1",
                    Rules = new Rule[]{
                    new Rule(){ Title="rule1" }
                } },
                new AnalysisSet(){
                    ProviderName = "productname2",
                    Rules = new Rule[]{
                    new Rule(){ Title="rule1" },
                    new Rule(){ Title="rule2" }
                } }
            };
    
            var sb = new StringBuilder();
            using (var sw = new StringWriter(sb))
            using (var xw = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true }))
            {
                new XElement("AnalaysisSets"
                    , allAnalysisSets
                        .Select(set => new XElement("AnalysisSet"
                                , new XAttribute("ProviderName", set.ProviderName)
                                , new XElement("Results"
                                    , set.Rules.Select(rule => rule.GetRuleState())
                                )
                            )
                        )
                ).WriteTo(xw);
            }
            Console.Write(sb.ToString());
            Console.ReadLine();
        }
    }
    
    public class AnalysisSet
    {
        public IEnumerable<Rule> Rules { get; set; }
    
        public string ProviderName { get; set; }
    }
    
    public class Rule
    {
        public string Title { get; set; }
    
        public XStreamingElement GetRuleState()
        {
            return new XStreamingElement("RuleResult",
                new XElement("Title", Title));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a XDocument that looks like this: XDocument outputDocument = new XDocument( new
I have an XDocument that looks similar to <root> <a> <b foo=1 bar=2 />
I have a DIV being created with Javascript that a slideshow is going into.
I have a map that is being created and it seems as part of
I have a form field (a series of checkboxes) that's being created dynamically from
I have a Word .DOCument that's being generated by a (classic ASP) server. It's
How do remove the BOM from an XML file that is being created? I
I have a PDF document that has an owner password set but no user
I have created PS script that queries the Event Logs on my Servers then
I have an image being created with gdimage, which has 40000 5x5 blocks linking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.