truthtablecontrol_user_cont.../TruthTableControl/LoadXML.cs
Eugen Höglinger bf4681b191 Initialize
- 'User Control'
- Zum Setzten einer Wahrheitstabelle für unterschiedliche Anwender
2023-02-02 14:55:20 +01:00

86 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
namespace Eugen.ESystem.Windows.Forms
{
internal class LoadXML
{
public string FileName { get; set; }
public string Topic { get; set; } //z.B. "NX-Portal"
public string Group { get; set; } //z.B. "NX 1953"
public string[] Keys { get; set; } //z.B. "UGII_ENV"
public string[] Values { get; set; } //z.B. "M:\ug\NX1953_NXTC\global\00_DEFAULTS\UGII\ugii_env.dat"
public void Load()
{
// Das Dokument in eine neue XElement-Instanz laden
XElement rootElement = XElement.Load(FileName);
// Auflistung für die Gruppe erzeugen
List<Topics> groups = new List<Topics>();
//Alle groups-Elemente einlesen und durchgehen
//var personElements = rootElement.Elements(Group);
var groupElements = rootElement.Elements();
int i = 0;
string[] temp = new string[5];
List<string> lkeys = new List<string>();
List<string> lvalues = new List<string>();
foreach (var groupElement in groupElements)
{
temp = groupElement.ToString().Split(' ');
if (String.IsNullOrEmpty(Group))
{
Group = ExtractGroup(temp);
}
lkeys.Add(ExtractKey(temp));
lvalues.Add(ExtractValue(temp));
i++;
}
string[] keys = new string[lkeys.Count];
string[] values = new string[lvalues.Count];
for (int j = 0; j < lkeys.Count; j++)
{
keys[j] = lkeys[j];
values[j] = lvalues[j];
}
Keys = keys;
Values = values;
}
private string ExtractGroup(string[] temp)
{
return temp[0].Remove(0, 1);
}
private string ExtractKey(string[] temp)
{
return temp[1].Remove(temp[1].IndexOf("="));
}
private string ExtractValue(string[] temp)
{
return temp[1].Remove(0, temp[1].IndexOf("=") + 1).Replace("\"", "");
}
}
class Topics
{
public string Key;
public string Value;
}
}