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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:08:00+00:00 2026-05-13T08:08:00+00:00

please help. I have this code, it’s my class to serialize\deserialize application settings. [XmlRoot(EvaStartupData)]

  • 0

please help. I have this code, it’s my class to serialize\deserialize application settings.

[XmlRoot("EvaStartupData")]
[Serializable] 
public class MyConfigClass
{
    public string ServerName { get; set; }
    public string Database { get; set; }
    public string UserName { get; set; }
    public string UserLogin { get; set; }


    public static void MyConfigLoad()
    {
        FileInfo fi = new FileInfo(myConfigFileName);
        if (fi.Exists)
        {
            XmlSerializer mySerializer = new XmlSerializer(myConfigClass.GetType());
            StreamReader myXmlReader = new StreamReader(myConfigFileName);
            try
            {

                myConfigClass = (MyConfigClass)mySerializer.Deserialize(myXmlReader);
                myXmlReader.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show("Ошибка сериализации MyConfigLoad\n" + e.Message);
            }

            finally
            {
                myXmlReader.Dispose();
            }
        }
    }

    public static void MyConfigSave()
    {
        XmlSerializer mySerializer = new XmlSerializer(myConfigClass.GetType());
        StreamWriter myXmlWriter = new StreamWriter(myConfigFileName);
        try
        {
            mySerializer.Serialize(myXmlWriter, myConfigClass);
        }
        catch (Exception e)
        {
            MessageBox.Show("Ошибка сериализации MyConfigSave\n" + e.Message);
        }

        finally
        {
            myXmlWriter.Dispose();
        }
    }

}

Serialization give’s me simple xml-structure:

<ServerName>navuhodonoser</ServerName>
<Database>matrix</Database>
<UserName>Mr.Smith</UserName>
<UserLogin>neo</UserLogin>

How must i modify my class to get this xml structure ?:

<Connection ServerName="navuhodonoser" Database="matrix" ....>
  • 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-13T08:08:00+00:00Added an answer on May 13, 2026 at 8:08 am

    By default the XmlSerializer will serialize all public properties as elements; to override that you’ll need to tag each property with [XmlAttribute] (from System.Xml.Serialization namespace) which will give you your desired output.

    For example:

    [XmlAttribute]
    public string ServerName { get; set; }
    
    [XmlAttribute]
    public string Database { get; set; }
    
    [XmlElement]
    public string UserName { get; set; }
    
    // Note: no attribute
    public string UserLogin { get; set; }
    

    will produce something like:

    <xml ServerName="Value" Database="Value">
        <UserName>Value</UserName>  <!-- Note that UserName was tagged with XmlElement, which matches the default behavior -->
        <UserLogin>Value</UserLogin>
    </xml>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 497k
  • Answers 497k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The manifest declares the entry point for the application, that… May 16, 2026 at 11:55 am
  • Editorial Team
    Editorial Team added an answer (defun shell-command-on-region-to-string (start end command) (with-output-to-string (shell-command-on-region start end command… May 16, 2026 at 11:55 am
  • Editorial Team
    Editorial Team added an answer You can use a format specifier to limit it to… May 16, 2026 at 11:55 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Please, help me with one problem. I have this code, for submitting form via
Please help me out with this. I have this small application to load txt
I hope someone can help me with the following... I have this code below
I have this code : var dp:Array = new Array(); for ( var i:int
I have this code to try and call a method from my controller in
I have this code and I would like to modify it if possible to
I have this code : <?php session_start(); echo .$_SESSION['eventnum'].; $urlRefresh = testremot.php; header(Refresh: 5;
I have this problem with my code, the page is redirecting and wouldn't stop..
I have this code: #define _WIN32_WINNT 0x0500 #include <cstdlib> #include <iostream> #include <windows.h> using
i have to use code this.setUp(http://www.remax.com/, *firefox); selenium.open(/404/index.aspx?aspxerrorpath=/public/pages/searchresults.aspx); slenium.click(link=Find a RE/MAX Office); selenium.waitForPageToLoad(30000); selenium.selectFrame(REMAX

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.