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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:38:40+00:00 2026-05-15T23:38:40+00:00

I want XML in the following format: <configuration><!– Only one configuration node –> <logging>…</logging><!–

  • 0

I want XML in the following format:

<configuration><!-- Only one configuration node -->
  <logging>...</logging><!-- Only one logging node -->
  <credentials>...</credentials><!-- One or more credentials nodes -->
  <credentials>...</credentials>
</configuration>

I’m trying to create a class Configuration that has the [Serializable] attribute. To serialize the credentials nodes, I have the following:

[XmlArray("configuration")]
[XmlArrayItem("credentials", typeof(CredentialsSection))]
public List<CredentialsSection> Credentials { get; set; }

However, when I serialize this to XML, the XML is in the following format:

<configuration>
  <logging>...</logging>
  <configuration><!-- Don't want credentials nodes nested in a second
                      configuration node -->
    <credentials>...</credentials>
    <credentials>...</credentials>
  </configuration>
</configuration>

If I remove the [XmlArray("configuration")] line, I get the following:

<configuration>
  <logging>...</logging>
  <Credentials><!-- Don't want credentials nodes nested in Credentials node -->
    <credentials>...</credentials>
    <credentials>...</credentials>
  </Credentials>
</configuration>

How can I serialize this the way I want, with multiple <credentials> nodes within the single root node <configuration>? I wanted to do this without having to implement IXmlSerializable and do custom serialization. This is how my class is described:

[Serializable]
[XmlRoot("configuration")]
public class Configuration : IEquatable<Configuration>
  • 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-15T23:38:42+00:00Added an answer on May 15, 2026 at 11:38 pm

    The following should serialize properly the way you want. The clue being [XmlElement("credentials")] on the list. I did this by taking your xml, generating a schema (xsd) from it in Visual Studio. Then running xsd.exe on the schema to generate a class. (And some small edits)

    public class CredentialsSection
    {
        public string Username { get; set; }
        public string Password { get; set; }
    }
    
    [XmlRoot(Namespace = "", IsNullable = false)]
    public class configuration
    {
        /// <remarks/>
        public string logging { get; set; }
    
        /// <remarks/>
        [XmlElement("credentials")]
        public List<CredentialsSection> credentials { get; set; }
    
        public string Serialize()
        {
            var credentialsSection = new CredentialsSection {Username = "a", Password = "b"};
            this.credentials = new List<CredentialsSection> {credentialsSection, credentialsSection};
            this.logging = "log this";
            XmlSerializer s = new XmlSerializer(this.GetType());
            StringBuilder sb = new StringBuilder();
            TextWriter w = new StringWriter(sb);
            s.Serialize(w, this);
            w.Flush();
            return sb.ToString();
        }
    }
    

    give the following output

    <?xml version="1.0" encoding="utf-16"?>
    <configuration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <logging>log this</logging>
      <credentials>
        <Username>a</Username>
        <Password>b</Password>
      </credentials>
      <credentials>
        <Username>a</Username>
        <Password>b</Password>
      </credentials>
    </configuration>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 498k
  • Answers 498k
  • 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 problem is not specifically with nil. It's that to_json… May 16, 2026 at 12:10 pm
  • Editorial Team
    Editorial Team added an answer I do not think (am quite sure that) you cannot… May 16, 2026 at 12:10 pm
  • Editorial Team
    Editorial Team added an answer Google is your friend on this one - see here May 16, 2026 at 12:10 pm

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

I want to write my xml with following format. How can i do it?I
I want to receive my response XML in following format... <PersonDetails> <Name>Ajay</Name> <Age>29</Age> <ContactDetails>
I have XML in the following format which I want to reformat: <blocks> <!--
I have an xml in the following format <root> <page> <title>text</title> <text attrib1=1>some text</text>
I have XML in the following format: <Products> <Product name=MyProduct1> <Components> <Component name=MyComponent1> <Teams>
I was planning to use an XML document to store configuration for my next
does anyone knows a file format for configuration files easy to read by humans?
I want to send a binary file to .net c# component in the following
Summary: How can I determine TFS source control configuration for a local folder. Explanation:

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.