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
  • 1 View
  • 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

Related Questions

I have this code: [Serializable] [XmlRoot(ISO_CCY_CODES)] public class IsoCurrencyCodes { public IsoCurrencyCodes() { IsoCodes
Could anyone please help me convert this code to vb.net, I have tried it
Please help me about this issue... In my application i have calender where user
Can anybody please help me with this as I have no idea why public
can you please help me with this issue the String class does not have
Please help me out with this. I have this small application to load txt
I have this code in my WCF Service: public class MyImage { public Image
Can somebody help me please, I have this code : $('childcat').setHTML('Loading...'); I would like
I have a small requirement.. Please someone help me I have this code to
i have this code in actions.class.php public function executeListmatches(sfWebRequest $request) { $form_values = $request->getParameter('match_form',

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.