Connectster.Shopify.ShopifyCommunicator.CleanupXmlForShopifySubmission C# (CSharp) Method

CleanupXmlForShopifySubmission() public static method

Add " type="array" " to elements that require it. Remove xsi:nil="true" elements.
public static CleanupXmlForShopifySubmission ( XmlDocument inDoc ) : XmlDocument
inDoc System.Xml.XmlDocument XmlDocument to be cleaned before submission to Shopify.
return System.Xml.XmlDocument
            public static XmlDocument CleanupXmlForShopifySubmission(XmlDocument inDoc)
            {
            const string withoutArray = @"\<[^/\>]*(options|images|variants){1}[^\>]*\>";
            const string addArray = @"<$1 type=""array"">";
            const string removeNil = @"\<[^\>]* xsi:nil=""(true|false){1}"" [^\<\>]*\>[\s]*";
            const string findDecimalTags = @"<(price){1}[^\>]*>";
            const string addTypeDecimal = @"<$1 type=""decimal"">";

            const string findIntegerTypeTags = @"<(grams|id|inventory-quantity|position|product-id){1}>";
            const string addTypeInteger = @"<$1 type=""integer"">";

            const string findBooleanTypeTags = @"<(taxable|requires-shipping){1}>";
            const string addTypeBoolean = @"<$1 type=""boolean"">";

            const string findDateTimeTypeTags = @"<(updated-at|created-at|published-at){1}>";
            const string addTypeDateTime = @"<$1 type=""datetime"">";

            const string removeXsi = @"xmlns:(xsd|xsi){1}=""[^""]*""";

            //Get the xmldocument as e string
            var sw = new StringWriter();
            var xw = new XmlTextWriter(sw);
            inDoc.WriteTo(xw);

            string xmlString = sw.ToString();
            xmlString = Regex.Replace(xmlString, removeXsi, String.Empty);
            xmlString = Regex.Replace(xmlString, removeNil, string.Empty);

            xmlString = Regex.Replace(xmlString, withoutArray, addArray);
            xmlString = Regex.Replace(xmlString, findDecimalTags, addTypeDecimal);
            xmlString = Regex.Replace(xmlString, findIntegerTypeTags, addTypeInteger);
            xmlString = Regex.Replace(xmlString, findBooleanTypeTags, addTypeBoolean);
            xmlString = Regex.Replace(xmlString, findDateTimeTypeTags, addTypeDateTime);

            var returnDoc = new XmlDocument();
            try
            {
                returnDoc.LoadXml(xmlString);
                return returnDoc;
            }
            catch
            {
                Logger.ErrorFormat(
                    "ShopifyCommunicator()::CleanupXmlForShopifySubmission(): Cleanup invalidated XML. Final string was {0}",
                    xmlString);
                return null;
            }
            }