Skip to content

Commit

Permalink
feat: Add static root properties to table
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirdock committed Sep 19, 2024
1 parent 4fed7ed commit f105b1a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
31 changes: 26 additions & 5 deletions DataTableConverter/Assisstant/importers/XmlImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal static void Import(string path, DatabaseHelper databaseHelper, Progress
int counter = 0;
SQLiteCommand insertCommand = null;
Dictionary<string, string> rowData = new Dictionary<string, string>();
Dictionary<string, string> staticColumns = new Dictionary<string, string>();
databaseHelper.CreateTable(new List<string>(), tableName);

XmlReaderSettings settings = new XmlReaderSettings
Expand All @@ -31,6 +32,21 @@ internal static void Import(string path, DatabaseHelper databaseHelper, Progress
};
XmlReader reader = XmlReader.Create(path, settings);
reader.Read();

// read static rows
if (reader.HasAttributes)
{
while (reader.MoveToNextAttribute())
{
string columnName = reader.LocalName;
staticColumns[columnName] = reader.Value;
rowData[columnName] = reader.Value;
overallColumns.Add(columnName);
databaseHelper.AddColumn(tableName, columnName);
}

}

// reading rows
while (reader.Read())
{
Expand All @@ -39,6 +55,11 @@ internal static void Import(string path, DatabaseHelper databaseHelper, Progress
{
rowData[key] = string.Empty;
}
// add static attributes
foreach (var pair in staticColumns)
{
rowData[pair.Key] = pair.Value;
}

HashSet<string> rowColumns = new HashSet<string>();
LoadRowData(reader, rowData, rowColumns);
Expand Down Expand Up @@ -125,8 +146,8 @@ private static string AlignArrayItemsAndPath(string parentPath, string parentNod
foreach (string previousColumnName in previousNewCols)
{
string col = previousColumnName.Substring(parentPath.Length + rowReader.LocalName.Length + 2);
string adjustedParentPath = newParentPath + (newParentPath == string.Empty ? string.Empty : " ");
string newColumnName = $"{adjustedParentPath}{rowReader.LocalName} 1 {col}";
string adjustedParentPath = newParentPath + (newParentPath == string.Empty ? string.Empty : "_");
string newColumnName = $"{adjustedParentPath}{rowReader.LocalName}_1_{col}";
string previousValue = rowData[previousColumnName];

rowColumns.Remove(previousColumnName);
Expand All @@ -145,20 +166,20 @@ private static string MergeColumnName(string columnName, string parentName, int
{
if(isParentList)
{
return $"{columnName} {itemNumber}";
return $"{columnName}_{itemNumber}";
}
return columnName;
}
if (isParentList)
{
return $"{parentName} {itemNumber} {columnName}";
return $"{parentName}_{itemNumber}_{columnName}";
}
if (columnName == string.Empty)
{
// value of an element
return parentName;
}
return $"{parentName} {columnName}";
return $"{parentName}_{columnName}";
}
}
}
2 changes: 1 addition & 1 deletion DataTableConverter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.42.0")]
[assembly: AssemblyFileVersion("1.0.43.0")]

0 comments on commit f105b1a

Please sign in to comment.