XML design for parsing in C# I am trying to design XML with configuration info so I can parse it into this code:

...
services.Configure&lt;IdentityOptions&gt;(options =&gt;
{
    // Password settings
    options.Password.RequireDigit = true;
    options.Password.RequiredLength = 8;
    options.Password.RequireNonAlphanumeric = false;
    options.Password.RequireUppercase = true;
    options.Password.RequireLowercase = false;
    options.Password.RequiredUniqueChars = 6;
});
...


I have already 4 versions of the XML code, but I don't know which one to choose:

&lt;identity&gt;
    &lt;!-- version 1 --&gt;
    &lt;password&gt;
        &lt;RequireDigit&gt;true&lt;/RequireDigit&gt;
        &lt;RequiredLength&gt;8&lt;/RequiredLength&gt;
        &lt;RequireNonAlphanumeric&gt;false&lt;/RequireNonAlphanumeric&gt;
        &lt;RequireUppercase&gt;true&lt;/RequireUppercase&gt;
        &lt;RequireLowercase&gt;false&lt;/RequireLowercase&gt;
        &lt;RequiredUniqueChars&gt;6&lt;/RequiredUniqueChars&gt;
    &lt;/password&gt;
    &lt;!-- version 2 --&gt;
    &lt;password   RequireDigit="true" 
                RequiredLength="8" 
                RequireNonAlphanumeric="false" 
                RequireUppercase="true" 
                RequireLowercase="false" 
                RequiredUniqueChars="6"
    /&gt;
    &lt;!-- version 3 --&gt;
    &lt;password&gt;
        &lt;RequireDigit value="true"/&gt;
        &lt;RequiredLength value="8"/&gt;
        &lt;RequireNonAlphanumeric value="false"/&gt;
        &lt;RequireUppercase value="true"/&gt;
        &lt;RequireLowercase value="false"/&gt;
        &lt;RequiredUniqueChars value="6"/&gt;
    &lt;/password&gt;
    &lt;!-- version 4 --&gt;
    &lt;password&gt;
        &lt;RequireDigit/&gt;
        &lt;RequiredLength value="8"/&gt;
        &lt;RequireUppercase/&gt;
        &lt;RequiredUniqueChars value="6"/&gt;
    &lt;/password&gt;
&lt;/identity&gt;



Are there any rules when to choose which one?
Or how to decide which is the best or the most suitable?
You are trying to recreate functionality that is already provided out of the box. 

Reference Configure an ASP.NET Core App

From documentation it supports providers for INI, JSON, and XML. 


  Each configuration value maps to a string key. There's built-in binding support to deserialize settings into a custom POCO object (a simple .NET class with properties).


Reference ASP.NET Core 1.0 Configuration Deep Dive

For XML, you need to add this NuGet package: Microsoft.Extensions.Configuration.Xml and the format that provider uses would look like this for your settings

Note: It matches closely to version 1 in your example

&lt;configuration&gt;
    &lt;identityOptions&gt;
        &lt;password&gt;
            &lt;RequireDigit&gt;true&lt;/RequireDigit&gt;
            &lt;RequiredLength&gt;8&lt;/RequiredLength&gt;
            &lt;RequireNonAlphanumeric&gt;false&lt;/RequireNonAlphanumeric&gt;
            &lt;RequireUppercase&gt;true&lt;/RequireUppercase&gt;
            &lt;RequireLowercase&gt;false&lt;/RequireLowercase&gt;
            &lt;RequiredUniqueChars&gt;6&lt;/RequiredUniqueChars&gt;
        &lt;/password&gt;
    &lt;/identity&gt;
&lt;/configuration&gt;


And the following would be added as part of configuration

//...
.AddXmlFile("appsettings.xml", optional: true, reloadOnChange: true)
//...


If using JSON then

{  
  "IdentityOptions": {
    "Password": {
      "RequireDigit": true
      "RequiredLength": 8
      "RequireNonAlphanumeric": false
      "RequireUppercase": true
      "RequireLowercase": false
      "RequiredUniqueChars": 6
    }
  }
}


And the following would be added as part of configuration

//...
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
//...


You appear to already be setting up IOptions, which is good.

//...
// Register the ConfigurationBuilder instance which IdentityOptions binds against.
services.Configure&lt;IdentityOptions&gt;(Configuration);

//...


This will allow constructor dependency injection with IOptions&lt;TOptions&gt; to access settings

private readonly IdentityOptions options;

public MyClass(IOptions&lt;IdentityOptions&gt; identity) {
    options = identity.Value;
}