private string GetCleanName(string name, Map.InputField field)
        {
            string cleanName          = name;
            var    replacementPattern = field.ReplacementRegexPattern;

            if (!string.IsNullOrWhiteSpace(replacementPattern))
            {
                var regex       = new System.Text.RegularExpressions.Regex(replacementPattern);
                var replacement = field.ReplacementText ?? string.Empty;
                cleanName = regex.Replace(cleanName, replacement);
            }

            if (field.Fields != null && field.Fields.Count > 0)
            {
                foreach (var item in field.Fields)
                {
                    replacementPattern = item.ReplacementRegexPattern;
                    if (!string.IsNullOrWhiteSpace(replacementPattern))
                    {
                        var regex       = new System.Text.RegularExpressions.Regex(replacementPattern);
                        var replacement = item.ReplacementText ?? string.Empty;
                        cleanName = regex.Replace(cleanName, replacement);
                    }
                }
            }
            return(cleanName);
        }
        private string GetCleanContent(HtmlNode node, Map.InputField field)
        {
            // Avoid modifying the original node
            var nodeClone = HtmlNode.CreateNode(node.OuterHtml);

            // Remove existing ASPNET forms (except contact-us's one which will be replaced later with the associated placeholder.
            var form = nodeClone.SelectSingleNode(@"//form[@id!='form_contact']");

            if (form != null)
            {
                var formParent = form.ParentNode;
                if (formParent != null)
                {
                    foreach (var item in form.ChildNodes.Where(x => x.Attributes["class"] == null || x.Attributes["class"].Value != "aspNetHidden"))
                    {
                        formParent.AppendChild(item.CloneNode(true));
                    }
                    formParent.RemoveChild(form);
                }
            }
            foreach (var item in field.Fields)
            {
                var nodesToBeReplaced = nodeClone.SelectNodes(item.XsltSelector);
                if (nodesToBeReplaced != null)
                {
                    foreach (var n in nodesToBeReplaced)
                    {
                        //n.ParentNode.ReplaceChild(HtmlNode.CreateNode(item.ReplacementText), n);
                        var replacementPattern = item.ReplacementRegexPattern;
                        if (string.IsNullOrWhiteSpace(replacementPattern))
                        {
                            n.ParentNode.ReplaceChild(HtmlNode.CreateNode(item.ReplacementText), n);
                        }
                        else
                        {
                            var regex        = new System.Text.RegularExpressions.Regex(replacementPattern);
                            var input        = n.InnerHtml;
                            var replacement  = item.ReplacementText ?? string.Empty;
                            var replacedText = regex.Replace(input, replacement);
                            var newNode      = HtmlNode.CreateNode(replacedText);
                            if (nodeClone == n)
                            {
                                nodeClone = newNode;
                            }
                            else
                            {
                                n.ParentNode.ReplaceChild(newNode, n);
                            }
                        }
                    }
                }
            }
            return(field.TextOnly ? new string(nodeClone.InnerText.Where(c => !char.IsControl(c)).ToArray()) : nodeClone.InnerHtml);
        }
        private string GetCleanContent(HtmlAttribute content, Map.InputField field)
        {
            var contentValue = HttpUtility.HtmlDecode(content.Value);

            foreach (var item in field.Fields)
            {
                var replacementPattern = item.ReplacementRegexPattern;
                if (!string.IsNullOrWhiteSpace(replacementPattern))
                {
                    var regex        = new System.Text.RegularExpressions.Regex(replacementPattern);
                    var input        = contentValue;
                    var replacement  = item.ReplacementText ?? string.Empty;
                    var replacedText = regex.Replace(input, replacement);
                    contentValue = replacedText;
                }
            }
            return(contentValue);
        }