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

  • Home
  • SEARCH
  • 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 8146733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:06:10+00:00 2026-06-06T14:06:10+00:00

I’ve managed to easily generate an XML file from a few classes, as shown

  • 0

I’ve managed to easily generate an XML file from a few classes, as shown below;

public class AllConfig : XMLEncapsulator
{
    [XmlElement("Database-Settings")]
    public DataBaseConfiguration databaseConfiguration { get; set; }
    [XmlElement("Merlin-Settings")]
    public MerlinConfiguration merlinConfiguration { get; set; }
}



public class DataBaseConfiguration : XMLEncapsulator
{
    public string dbIP { get; set; }
    public int ?port { get; set; }
    public string username { get; set; }
    public string password { get; set; }
}

public class MerlinConfiguration : XMLEncapsulator
{
    public string MerlinIP { get; set; }
    public int ?MerlinPort { get; set; }
    public int ?RecievingPort { get; set; }
}


// load classes with information, then;

  try
        {
            allConfig.databaseConfiguration = dbConfig;
            allConfig.merlinConfiguration = merlinConfig;
            allConfig.Save();
        }
        catch (Exception ErrorFinalisingSave)
        {
            MessageBox.Show(ErrorFinalisingSave.Message + "3");
        }

This works perfectly and gives me:

<AllConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <databaseConfiguration>
 <dbIP></dbIP>
 <port></port>
 <username></username>
 <password></password>
</databaseConfiguration>
<merlinConfiguration>
 <MerlinIP></MerlinIP>
 <MerlinPort></MerlinPort>
 <RecievingPort></RecievingPort>
 </merlinConfiguration>
</AllConfig>

However, how do i go about retrieving this back into my forms? so i’ve got something like this, but i can’t seem to get it to work;

  AllConfig allConfig;
    DataBaseConfiguration dbConfig;
    MerlinConfiguration merlinConfig;

  //need to load here.

//check if values loaded are null, and then load them if they exist into textboxes and such.

should i load the two config classes and then assign them to the overall config class? or do i need to load the overall class and assign the sub-config classes off this, like so;

 allConfig = new AllConfig();

                dbConfig = new DataBaseConfiguration();
                merlinConfig = new MerlinConfiguration();

                allConfig.databaseConfiguration = dbConfig;
                allConfig.merlinConfiguration = merlinConfig;

                allConfig.databaseConfiguration.Load();
                allConfig.merlinConfiguration.Load();

edit: heres my loading method;

 public virtual void Load()
{
    if (File.Exists(DeviceManager.path))
    {
        StreamReader sr = new StreamReader(DeviceManager.path);
        XmlTextReader xr = new XmlTextReader(sr);
        XmlSerializer xs = new XmlSerializer(this.GetType());
        object c;
        if (xs.CanDeserialize(xr))
        {
            c = xs.Deserialize(xr);
            Type t = this.GetType();
            PropertyInfo[] properties = t.GetProperties();
            foreach (PropertyInfo p in properties)
            {
                p.SetValue(this, p.GetValue(c, null), null);
            }
        }
        xr.Close();
        sr.Close();
    }
}
  • 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-06T14:06:13+00:00Added an answer on June 6, 2026 at 2:06 pm

    Fixed my own problem guys. It was how i was loading it, in the end i ended up doing it like so;

    allConfig = new AllConfig();
                    dbConfig = new DataBaseConfiguration();
                    merlinConfig = new MerlinConfiguration();
                    allConfig.databaseConfiguration = dbConfig;
                    allConfig.merlinConfiguration = merlinConfig;
                    allConfig.Load();
    

    so i created an instance of the class i serialise, then created the classes which is consists off, and assigned these to the main class. Then i loaded the main class (which i assume through the serializer populates the classes it consists off, and then i accessed them like so;

    allConfig.databaseConfiguration.port;
    allConfig.databaseConfiguration.username;
    

    and so on. thanks for the advice though guys, really helped me out.

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

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Does anyone know how can I replace this 2 symbol below from the string
I'm parsing an XML file, the creators of it stuck in a bunch social
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported

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.