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 6609325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:42:16+00:00 2026-05-25T19:42:16+00:00

This question may be asked or answered before but I feel that none of

  • 0

This question may be asked or answered before but I feel that none of the hits really apply.

I would like to create a little class with attributes which will correspond to name and attributes in a output familiar to xml stream. The class should help the program to create a xml-alike string.

string test = "<graph caption='SomeHeader' attribute9='#someotherinfo'>" +
                 "<set name='2004' value='37800' color='AFD8F8' />" +
                 "<set name='2005' value='21900' color='F6BD0F' />" +
                 "<set name='2006' value='32900' color='8BBA00' />" +
                  "<set name='2007' value='39800' color='FF8E46' />" +
              "</graph>";

I think you got the idea. I have a static amount of known attributes which will be used in the tags. The only Tags here is set and graph.

I would like to do something like this,

Helper o = new Helper()
List<Tag> tag = new List<Tag>();
foreach (var someitem in somedatabaseresult)
{
   tag.Add(New Graph() { Caption = someitem.field , attribute9 = someitem.otherField });
   foreach (var detail in someitem)
   {
     tag.Add(new Set() { name = detail.Year, value = detail.Value color = detail.Color });
   }
}
o.Generate(); // Which will create the structure of result sample above

// and for future extension.. 
// o.GenerateXml();
// o.GenerateJson();

Please remember that this code is pesudo, just taken from my head. A result of that I have some ideas but it take a day to code and test what best (or whorse).

What would be best practice to solve this task?

[EDIT]
This mysterious “Helper” is the (unluckily typed) class who contains a list of Graph, a list of Set and also (what I think about) contains all available attributes per Graph/Set object. The work of the foreach-loops above are mentioned to fill the Helper class with the data.

[EDIT2]
Result here,
https://gist.github.com/1233331

  • 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-05-25T19:42:16+00:00Added an answer on May 25, 2026 at 7:42 pm

    Why not just create a couple of classes: Graph and Set. Graph would have a property of List<Set>.

    In your foreach you can then create an instance or Graph and add instances of Set to its list.

    When you’re done use the XML Serializer to serialize the Graph object out to XML. Nice and easy to then output to another format as well if your needs change later e.g. serialize to JSON.

    Edit following comment:

    From top my head so may not be 100% correct…

    var myGraph = BuildMeAGraph();
    var serializer = new XmlSerializer(typeof(Graph));
    var writer = XmlWriter.Create("myfile.xml");
    serializer.Serialize(writer, myGraph);
    

    But something like that should write it out to a file. If you want the XML in memory then write it out to an XMLTextWriter based on a memory stream instead and then you can write the contents to a string variable or do whatever you need with it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been asked and answered before, but none of the
I'm aware that this question may have been asked before, but I still haven't
I've seen this question asked before but it seems that the answer may be
This question may have been asked before, but I had trouble finding an answer,
This question may sound familiar but not quite the same as asked before. I
You may think this question is like this question asked on StackOverflow earlier. But
Ok, this may look like a previous asked question, but I already googled this
This question may have been asked before, but I'm starting to get into game
This question may have been asked before, but it's not in the same manner.
First, this question may have been asked before, but I'm not sure what phrase

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.