/// <summary>
/// Parse XML file
/// </summary>
/// <param name="filePath"></param>
public Tuple<List<FieldImports>, bool> ParseXmlFile(string filePath)
{
var columnList = new List<FieldImports>();
try
{
if (!File.Exists(filePath))
{
throw new PersistenceValidationException("Validation Error",
new List<BrokenRule>
{
new BrokenRule(BrokenRuleEnum.Data.ToStringValue(), "FileUpload", "File not found.")
});
}
var xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);
if (xmlDoc.DocumentElement != null)
foreach (XmlNode xmlNode in xmlDoc.DocumentElement)
{
//column name
var columnsName = xmlNode.Name;
//column value
var value = xmlNode.InnerText;
var fieldImports = new FieldImports
{
ColumnName = columnsName,
ColumnValue = value
};
columnList.Add(fieldImports);
}
return new Tuple<List<FieldImports>, bool>(columnList, false);
}
catch (XmlException)
{
throw new PersistenceValidationException("Validation Error", new List<BrokenRule>
{
new BrokenRule("InvalidXml", "Invalid Xml file")
});
}
}
/// Parse XML file
/// </summary>
/// <param name="filePath"></param>
public Tuple<List<FieldImports>, bool> ParseXmlFile(string filePath)
{
var columnList = new List<FieldImports>();
try
{
if (!File.Exists(filePath))
{
throw new PersistenceValidationException("Validation Error",
new List<BrokenRule>
{
new BrokenRule(BrokenRuleEnum.Data.ToStringValue(), "FileUpload", "File not found.")
});
}
var xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);
if (xmlDoc.DocumentElement != null)
foreach (XmlNode xmlNode in xmlDoc.DocumentElement)
{
//column name
var columnsName = xmlNode.Name;
//column value
var value = xmlNode.InnerText;
var fieldImports = new FieldImports
{
ColumnName = columnsName,
ColumnValue = value
};
columnList.Add(fieldImports);
}
return new Tuple<List<FieldImports>, bool>(columnList, false);
}
catch (XmlException)
{
throw new PersistenceValidationException("Validation Error", new List<BrokenRule>
{
new BrokenRule("InvalidXml", "Invalid Xml file")
});
}
}