Exemplo n.º 1
0
        public void LoadConfigurationFromXml(string configurationFile)
        {
            var xmlDocument = new XmlDocument();

            xmlDocument.Load(configurationFile);

            var nodes = xmlDocument.SelectNodes("/configuration/parser/expressionReplacements/expressionReplacement");

            foreach (XmlNode node in nodes)
            {
                // Get the expression,
                var expression = node.SelectSingleNode("@expression").Value;
                expression = expression.Replace("\\n", "\n");

                // Get the replacement.
                var replacement = node.SelectSingleNode("@replacement").Value;
                replacement = replacement.Replace("\\n", "\n");

                // Build the expression replacement.
                var expressionReplacement = new ExpressionReplacement(expression, replacement);
                ExpressionReplacements.Add(expressionReplacement);
            }

            nodes = xmlDocument.SelectNodes("/configuration/tags/tag");
            foreach (XmlNode node in nodes)
            {
                var tag                    = node.SelectSingleNode("@name").InnerText;
                var replacement            = node.SelectSingleNode("@replacement").InnerText;
                var alternativeReplacement =
                    node.SelectSingleNode("@alternativeReplacement") != null
                        ? node.SelectSingleNode("@alternativeReplacement").InnerText
                        : null;

                try
                {
                    var parseContent = Boolean.Parse(node.SelectSingleNode("@parseContent").InnerText);
                    TagConfigurations.Add(new TagConfiguration(tag, replacement, alternativeReplacement, parseContent));
                }
                catch (NullReferenceException)
                {
                    TagConfigurations.Add(new TagConfiguration(tag, replacement, alternativeReplacement));
                }
            }
        }
        public void LoadConfigurationFromXml(string configurationFile)
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.Load(configurationFile);

            var nodes = xmlDocument.SelectNodes("/configuration/parser/expressionReplacements/expressionReplacement");
            foreach (XmlNode node in nodes)
            {
                // Get the expression,
                var expression = node.SelectSingleNode("@expression").Value;
                expression = expression.Replace("\\n", "\n");

                // Get the replacement.
                var replacement = node.SelectSingleNode("@replacement").Value;
                replacement = replacement.Replace("\\n", "\n");

                // Build the expression replacement.
                var expressionReplacement = new ExpressionReplacement(expression, replacement);
                ExpressionReplacements.Add(expressionReplacement);
            }

            nodes = xmlDocument.SelectNodes("/configuration/tags/tag");
            foreach (XmlNode node in nodes)
            {
                var tag = node.SelectSingleNode("@name").InnerText;
                var replacement = node.SelectSingleNode("@replacement").InnerText;
                var alternativeReplacement =
                    node.SelectSingleNode("@alternativeReplacement") != null
                        ? node.SelectSingleNode("@alternativeReplacement").InnerText
                        : null;
                try
                {
                    var parseContent = Boolean.Parse(node.SelectSingleNode("@parseContent").InnerText);
                    TagConfigurations.Add(new TagConfiguration(tag, replacement, alternativeReplacement, parseContent));
                }
                catch (NullReferenceException)
                {
                    TagConfigurations.Add(new TagConfiguration(tag, replacement, alternativeReplacement));
                }
            }
        }