app.config の使用について少し迷っています....ini ファイルをずっと使用してきましたが、変更したいと思います... これが私の .ini の外観です
[Clients]
1 = Client1
2 = Client 2
[Client1]
Employees = 4
1 = Employee1
2 = Employee2
3 = Employee3
4 = Employee4
[Client2]
Employees = 3
1 = Employee1
2 = Employee2
3 = Employee3
次に、いくつかの for ループを使用していました。最初に [Clients] を検索し、その中でクライアントの場合、何人の従業員がいるかを検索し、次に、従業員ごとに何かを行います...
この .ini をこのようなものに変換するにはどうすればよいですか
<Clients>
<name = "client1">
<Employees>
<name = "employee1" />
<name = "employee2" />
<name = "employee3" />
<name = "employee4" />
</Employees>
<name = "client2">
<Employees>
<name = "employee1" />
<name = "employee2" />
<name = "employee3" />
</Employees>
</Clients>
そして、そのapp.configを使用してループで物事を行います
アドバイスありがとう。
UPDATE 私はこのlinq to xmlコードを試しました
XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XComment("Configuración Checkcenter"),
new XElement("Entidad",
new XAttribute("nombre",cmbEntidad.Text),
new XElement("Servicios",
new XElement("nombre", cmbServicio.Text))));
doc.Save("settings.xml");
それは動作し、私にこれを返します:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--My Settings-->
<Client name="Client1">
<Employees>
<name>Employee1</name>
</Employees>
</Entidad>
しかし、それは常に従業員の私の名前を置き換えます...それが存在しない場合、新しいアイテムを追加するにはどうすればよいですか? つまり、クライアントの Employees に新しい項目が存在しない場合は追加します。