Skip to content

Commit

Permalink
fix: Consider xml declarations and empty elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirdock committed Oct 3, 2024
1 parent 6bbecc6 commit 97b112d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion DataTableConverter/Assisstant/importers/XmlImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ internal static void Import(string path, DatabaseHelper databaseHelper, Progress
XmlReader reader = XmlReader.Create(path, settings);
reader.Read();

// skip header information
if(reader.NodeType == XmlNodeType.XmlDeclaration)
{
reader.Read();
}

// read static columns
if (reader.HasAttributes)
{
Expand Down Expand Up @@ -83,7 +89,8 @@ internal static HashSet<string> LoadRowData(XmlReader rowReader, Dictionary<stri
{
HashSet<string> newCols = new HashSet<string>();
string rowElementName = rowReader.LocalName;
if(rowReader.NodeType == XmlNodeType.EndElement)
bool isEmptyElement = rowReader.IsEmptyElement;
if (rowReader.NodeType == XmlNodeType.EndElement)
{
return newCols;
}
Expand All @@ -99,10 +106,16 @@ internal static HashSet<string> LoadRowData(XmlReader rowReader, Dictionary<stri

}

if (isEmptyElement)
{
return newCols;
}

// Read Cells
int itemNumber = 1;
string previousElement = null;
HashSet<string> previousNewCols = new HashSet<string>();

while (rowReader.Read() && rowReader.LocalName != rowElementName && rowReader.NodeType != XmlNodeType.EndElement)
{
bool isParentList = previousElement == rowReader.LocalName;
Expand All @@ -125,6 +138,7 @@ internal static HashSet<string> LoadRowData(XmlReader rowReader, Dictionary<stri
}
itemNumber++;
}

if(itemNumber == 1)
{
// empty value
Expand Down
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.44.0")]
[assembly: AssemblyFileVersion("1.0.45.0")]

0 comments on commit 97b112d

Please sign in to comment.