XML design for parsing in C# [closed]
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
3
down vote
favorite
I am trying to design XML with configuration info so I can parse it into this code:
...
services.Configure<IdentityOptions>(options =>
// 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:
<identity>
<!-- version 1 -->
<password>
<RequireDigit>true</RequireDigit>
<RequiredLength>8</RequiredLength>
<RequireNonAlphanumeric>false</RequireNonAlphanumeric>
<RequireUppercase>true</RequireUppercase>
<RequireLowercase>false</RequireLowercase>
<RequiredUniqueChars>6</RequiredUniqueChars>
</password>
<!-- version 2 -->
<password RequireDigit="true"
RequiredLength="8"
RequireNonAlphanumeric="false"
RequireUppercase="true"
RequireLowercase="false"
RequiredUniqueChars="6"
/>
<!-- version 3 -->
<password>
<RequireDigit value="true"/>
<RequiredLength value="8"/>
<RequireNonAlphanumeric value="false"/>
<RequireUppercase value="true"/>
<RequireLowercase value="false"/>
<RequiredUniqueChars value="6"/>
</password>
<!-- version 4 -->
<password>
<RequireDigit/>
<RequiredLength value="8"/>
<RequireUppercase/>
<RequiredUniqueChars value="6"/>
</password>
</identity>
- Are there any rules when to choose which one?
- Or how to decide which is the best or the most suitable?
c# comparative-review xml configuration asp.net-core
closed as off-topic by Sam Onela, Raystafarian, Dannnno, Toby Speight, Zeta Mar 27 at 12:26
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." â Sam Onela, Raystafarian, Dannnno, Toby Speight
add a comment |Â
up vote
3
down vote
favorite
I am trying to design XML with configuration info so I can parse it into this code:
...
services.Configure<IdentityOptions>(options =>
// 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:
<identity>
<!-- version 1 -->
<password>
<RequireDigit>true</RequireDigit>
<RequiredLength>8</RequiredLength>
<RequireNonAlphanumeric>false</RequireNonAlphanumeric>
<RequireUppercase>true</RequireUppercase>
<RequireLowercase>false</RequireLowercase>
<RequiredUniqueChars>6</RequiredUniqueChars>
</password>
<!-- version 2 -->
<password RequireDigit="true"
RequiredLength="8"
RequireNonAlphanumeric="false"
RequireUppercase="true"
RequireLowercase="false"
RequiredUniqueChars="6"
/>
<!-- version 3 -->
<password>
<RequireDigit value="true"/>
<RequiredLength value="8"/>
<RequireNonAlphanumeric value="false"/>
<RequireUppercase value="true"/>
<RequireLowercase value="false"/>
<RequiredUniqueChars value="6"/>
</password>
<!-- version 4 -->
<password>
<RequireDigit/>
<RequiredLength value="8"/>
<RequireUppercase/>
<RequiredUniqueChars value="6"/>
</password>
</identity>
- Are there any rules when to choose which one?
- Or how to decide which is the best or the most suitable?
c# comparative-review xml configuration asp.net-core
closed as off-topic by Sam Onela, Raystafarian, Dannnno, Toby Speight, Zeta Mar 27 at 12:26
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." â Sam Onela, Raystafarian, Dannnno, Toby Speight
2
Clarification needed. The code snippet looks like .net-core startup code. This would lead me to ask why XML and not JSON? Next I am uncertain what you want reviews here?
â Nkosi
Mar 21 at 10:21
Yes, it is .net-core startup file. I want to use XML because except of information for the startup file, the XML file contains also other data (I provided just part of the whole file). So I want to know other's opinion on which version of XML data format is the best / is used.
â sapoi
Mar 21 at 10:32
3
You don't know this yet but you wantJSON
.
â t3chb0t
Mar 21 at 10:49
2
And why would I want JSON?
â sapoi
Mar 21 at 10:53
2
It's easier to read, easier to maintain, lighter, it's natively supported by asp.net-core, and there is only one way for storing your configuration so your question would answer itself with json.
â t3chb0t
Mar 21 at 12:01
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I am trying to design XML with configuration info so I can parse it into this code:
...
services.Configure<IdentityOptions>(options =>
// 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:
<identity>
<!-- version 1 -->
<password>
<RequireDigit>true</RequireDigit>
<RequiredLength>8</RequiredLength>
<RequireNonAlphanumeric>false</RequireNonAlphanumeric>
<RequireUppercase>true</RequireUppercase>
<RequireLowercase>false</RequireLowercase>
<RequiredUniqueChars>6</RequiredUniqueChars>
</password>
<!-- version 2 -->
<password RequireDigit="true"
RequiredLength="8"
RequireNonAlphanumeric="false"
RequireUppercase="true"
RequireLowercase="false"
RequiredUniqueChars="6"
/>
<!-- version 3 -->
<password>
<RequireDigit value="true"/>
<RequiredLength value="8"/>
<RequireNonAlphanumeric value="false"/>
<RequireUppercase value="true"/>
<RequireLowercase value="false"/>
<RequiredUniqueChars value="6"/>
</password>
<!-- version 4 -->
<password>
<RequireDigit/>
<RequiredLength value="8"/>
<RequireUppercase/>
<RequiredUniqueChars value="6"/>
</password>
</identity>
- Are there any rules when to choose which one?
- Or how to decide which is the best or the most suitable?
c# comparative-review xml configuration asp.net-core
I am trying to design XML with configuration info so I can parse it into this code:
...
services.Configure<IdentityOptions>(options =>
// 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:
<identity>
<!-- version 1 -->
<password>
<RequireDigit>true</RequireDigit>
<RequiredLength>8</RequiredLength>
<RequireNonAlphanumeric>false</RequireNonAlphanumeric>
<RequireUppercase>true</RequireUppercase>
<RequireLowercase>false</RequireLowercase>
<RequiredUniqueChars>6</RequiredUniqueChars>
</password>
<!-- version 2 -->
<password RequireDigit="true"
RequiredLength="8"
RequireNonAlphanumeric="false"
RequireUppercase="true"
RequireLowercase="false"
RequiredUniqueChars="6"
/>
<!-- version 3 -->
<password>
<RequireDigit value="true"/>
<RequiredLength value="8"/>
<RequireNonAlphanumeric value="false"/>
<RequireUppercase value="true"/>
<RequireLowercase value="false"/>
<RequiredUniqueChars value="6"/>
</password>
<!-- version 4 -->
<password>
<RequireDigit/>
<RequiredLength value="8"/>
<RequireUppercase/>
<RequiredUniqueChars value="6"/>
</password>
</identity>
- Are there any rules when to choose which one?
- Or how to decide which is the best or the most suitable?
c# comparative-review xml configuration asp.net-core
edited Mar 24 at 7:14
Vadim Ovchinnikov
1,0101417
1,0101417
asked Mar 21 at 9:04
sapoi
191
191
closed as off-topic by Sam Onela, Raystafarian, Dannnno, Toby Speight, Zeta Mar 27 at 12:26
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." â Sam Onela, Raystafarian, Dannnno, Toby Speight
closed as off-topic by Sam Onela, Raystafarian, Dannnno, Toby Speight, Zeta Mar 27 at 12:26
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." â Sam Onela, Raystafarian, Dannnno, Toby Speight
2
Clarification needed. The code snippet looks like .net-core startup code. This would lead me to ask why XML and not JSON? Next I am uncertain what you want reviews here?
â Nkosi
Mar 21 at 10:21
Yes, it is .net-core startup file. I want to use XML because except of information for the startup file, the XML file contains also other data (I provided just part of the whole file). So I want to know other's opinion on which version of XML data format is the best / is used.
â sapoi
Mar 21 at 10:32
3
You don't know this yet but you wantJSON
.
â t3chb0t
Mar 21 at 10:49
2
And why would I want JSON?
â sapoi
Mar 21 at 10:53
2
It's easier to read, easier to maintain, lighter, it's natively supported by asp.net-core, and there is only one way for storing your configuration so your question would answer itself with json.
â t3chb0t
Mar 21 at 12:01
add a comment |Â
2
Clarification needed. The code snippet looks like .net-core startup code. This would lead me to ask why XML and not JSON? Next I am uncertain what you want reviews here?
â Nkosi
Mar 21 at 10:21
Yes, it is .net-core startup file. I want to use XML because except of information for the startup file, the XML file contains also other data (I provided just part of the whole file). So I want to know other's opinion on which version of XML data format is the best / is used.
â sapoi
Mar 21 at 10:32
3
You don't know this yet but you wantJSON
.
â t3chb0t
Mar 21 at 10:49
2
And why would I want JSON?
â sapoi
Mar 21 at 10:53
2
It's easier to read, easier to maintain, lighter, it's natively supported by asp.net-core, and there is only one way for storing your configuration so your question would answer itself with json.
â t3chb0t
Mar 21 at 12:01
2
2
Clarification needed. The code snippet looks like .net-core startup code. This would lead me to ask why XML and not JSON? Next I am uncertain what you want reviews here?
â Nkosi
Mar 21 at 10:21
Clarification needed. The code snippet looks like .net-core startup code. This would lead me to ask why XML and not JSON? Next I am uncertain what you want reviews here?
â Nkosi
Mar 21 at 10:21
Yes, it is .net-core startup file. I want to use XML because except of information for the startup file, the XML file contains also other data (I provided just part of the whole file). So I want to know other's opinion on which version of XML data format is the best / is used.
â sapoi
Mar 21 at 10:32
Yes, it is .net-core startup file. I want to use XML because except of information for the startup file, the XML file contains also other data (I provided just part of the whole file). So I want to know other's opinion on which version of XML data format is the best / is used.
â sapoi
Mar 21 at 10:32
3
3
You don't know this yet but you want
JSON
.â t3chb0t
Mar 21 at 10:49
You don't know this yet but you want
JSON
.â t3chb0t
Mar 21 at 10:49
2
2
And why would I want JSON?
â sapoi
Mar 21 at 10:53
And why would I want JSON?
â sapoi
Mar 21 at 10:53
2
2
It's easier to read, easier to maintain, lighter, it's natively supported by asp.net-core, and there is only one way for storing your configuration so your question would answer itself with json.
â t3chb0t
Mar 21 at 12:01
It's easier to read, easier to maintain, lighter, it's natively supported by asp.net-core, and there is only one way for storing your configuration so your question would answer itself with json.
â t3chb0t
Mar 21 at 12:01
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
7
down vote
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
<configuration>
<identityOptions>
<password>
<RequireDigit>true</RequireDigit>
<RequiredLength>8</RequiredLength>
<RequireNonAlphanumeric>false</RequireNonAlphanumeric>
<RequireUppercase>true</RequireUppercase>
<RequireLowercase>false</RequireLowercase>
<RequiredUniqueChars>6</RequiredUniqueChars>
</password>
</identity>
</configuration>
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<IdentityOptions>(Configuration);
//...
This will allow constructor dependency injection with IOptions<TOptions>
to access settings
private readonly IdentityOptions options;
public MyClass(IOptions<IdentityOptions> identity)
options = identity.Value;
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
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
<configuration>
<identityOptions>
<password>
<RequireDigit>true</RequireDigit>
<RequiredLength>8</RequiredLength>
<RequireNonAlphanumeric>false</RequireNonAlphanumeric>
<RequireUppercase>true</RequireUppercase>
<RequireLowercase>false</RequireLowercase>
<RequiredUniqueChars>6</RequiredUniqueChars>
</password>
</identity>
</configuration>
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<IdentityOptions>(Configuration);
//...
This will allow constructor dependency injection with IOptions<TOptions>
to access settings
private readonly IdentityOptions options;
public MyClass(IOptions<IdentityOptions> identity)
options = identity.Value;
add a comment |Â
up vote
7
down vote
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
<configuration>
<identityOptions>
<password>
<RequireDigit>true</RequireDigit>
<RequiredLength>8</RequiredLength>
<RequireNonAlphanumeric>false</RequireNonAlphanumeric>
<RequireUppercase>true</RequireUppercase>
<RequireLowercase>false</RequireLowercase>
<RequiredUniqueChars>6</RequiredUniqueChars>
</password>
</identity>
</configuration>
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<IdentityOptions>(Configuration);
//...
This will allow constructor dependency injection with IOptions<TOptions>
to access settings
private readonly IdentityOptions options;
public MyClass(IOptions<IdentityOptions> identity)
options = identity.Value;
add a comment |Â
up vote
7
down vote
up vote
7
down vote
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
<configuration>
<identityOptions>
<password>
<RequireDigit>true</RequireDigit>
<RequiredLength>8</RequiredLength>
<RequireNonAlphanumeric>false</RequireNonAlphanumeric>
<RequireUppercase>true</RequireUppercase>
<RequireLowercase>false</RequireLowercase>
<RequiredUniqueChars>6</RequiredUniqueChars>
</password>
</identity>
</configuration>
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<IdentityOptions>(Configuration);
//...
This will allow constructor dependency injection with IOptions<TOptions>
to access settings
private readonly IdentityOptions options;
public MyClass(IOptions<IdentityOptions> identity)
options = identity.Value;
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
<configuration>
<identityOptions>
<password>
<RequireDigit>true</RequireDigit>
<RequiredLength>8</RequiredLength>
<RequireNonAlphanumeric>false</RequireNonAlphanumeric>
<RequireUppercase>true</RequireUppercase>
<RequireLowercase>false</RequireLowercase>
<RequiredUniqueChars>6</RequiredUniqueChars>
</password>
</identity>
</configuration>
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<IdentityOptions>(Configuration);
//...
This will allow constructor dependency injection with IOptions<TOptions>
to access settings
private readonly IdentityOptions options;
public MyClass(IOptions<IdentityOptions> identity)
options = identity.Value;
edited Mar 21 at 13:17
answered Mar 21 at 12:50
Nkosi
1,870619
1,870619
add a comment |Â
add a comment |Â
2
Clarification needed. The code snippet looks like .net-core startup code. This would lead me to ask why XML and not JSON? Next I am uncertain what you want reviews here?
â Nkosi
Mar 21 at 10:21
Yes, it is .net-core startup file. I want to use XML because except of information for the startup file, the XML file contains also other data (I provided just part of the whole file). So I want to know other's opinion on which version of XML data format is the best / is used.
â sapoi
Mar 21 at 10:32
3
You don't know this yet but you want
JSON
.â t3chb0t
Mar 21 at 10:49
2
And why would I want JSON?
â sapoi
Mar 21 at 10:53
2
It's easier to read, easier to maintain, lighter, it's natively supported by asp.net-core, and there is only one way for storing your configuration so your question would answer itself with json.
â t3chb0t
Mar 21 at 12:01