diff --git a/XML_Adapter/CRUD/Create.cs b/XML_Adapter/CRUD/Create.cs index a593603..f7621cb 100644 --- a/XML_Adapter/CRUD/Create.cs +++ b/XML_Adapter/CRUD/Create.cs @@ -30,6 +30,7 @@ using BH.oM.Adapters.XML.Enums; using BH.oM.Adapter; +using System.IO; namespace BH.Adapter.XML { @@ -50,23 +51,50 @@ protected override bool ICreate(IEnumerable objects, ActionConfig actionCo return false; } + bool success = false; + switch(config.Schema) { case Schema.CSProject: - return CreateCSProject(objects, config); + success = CreateCSProject(objects, config); + break; case Schema.GBXML: - return CreateGBXML(objects, config); + success = CreateGBXML(objects, config); + break; case Schema.KML: - return CreateKML(objects, config); + success = CreateKML(objects, config); + break; case Schema.EnergyPlusLoads: BH.Engine.Base.Compute.RecordError("The EnergyPlusLoads Schema is not supported for push operations at this time"); - return false; + success = false; + break; case Schema.Bluebeam: BH.Engine.Base.Compute.RecordError("The Bluebeam markup schema is not supported for push operations at this time."); - return false; + success = false; + break; default: - return CreateDefault(objects, config); + success = CreateDefault(objects, config); + break; } + + if (success && config.RemoveNils) + RemoveNil(_fileSettings); + + return success; + } + + private static bool RemoveNil(FileSettings file) + { + var path = Path.Combine(file.Directory, file.FileName); + var xmlFile = File.ReadAllLines(path); + + xmlFile = xmlFile.Where(x => !x.Trim().Contains("xsi:nil")).ToArray(); + xmlFile = xmlFile.Where(x => x != null).ToArray(); + + File.Delete(path); + File.WriteAllLines(path, xmlFile); + + return true; } } } diff --git a/XML_oM/XMLConfig.cs b/XML_oM/XMLConfig.cs index d435298..4edb50c 100644 --- a/XML_oM/XMLConfig.cs +++ b/XML_oM/XMLConfig.cs @@ -34,15 +34,17 @@ namespace BH.oM.Adapters.XML { - [Description("Define configuration settings for pushing and pulling XML files using the XML Adapter")] + [Description("Define configuration settings for pushing and pulling XML files using the XML Adapter.")] public class XMLConfig : ActionConfig { - [Description("Define the schema which the XML Adapter should be operating with")] + [Description("Define the schema which the XML Adapter should be operating with.")] public virtual Schema Schema { get; set; } = Schema.Undefined; - [Description("Set optional settings to use when pushing or pulling XML based on the chosen schema")] + [Description("Set optional settings to use when pushing or pulling XML based on the chosen schema.")] public virtual IXMLSettings Settings { get; set; } = null; + [Description("Determine whether 'nil' XML attributes should be removed when pushing to an XML file.")] + public virtual bool RemoveNils { get; set; } = false; } }