当前位置: 首页>>代码示例>>C#>>正文


C# XmlElement.SelectSingleElement方法代码示例

本文整理汇总了C#中System.Xml.XmlElement.SelectSingleElement方法的典型用法代码示例。如果您正苦于以下问题:C# XmlElement.SelectSingleElement方法的具体用法?C# XmlElement.SelectSingleElement怎么用?C# XmlElement.SelectSingleElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XmlElement的用法示例。


在下文中一共展示了XmlElement.SelectSingleElement方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ModularLanguageDefinition

        public ModularLanguageDefinition(XmlElement configurationElement)
        {
            Contract.Requires<ArgumentNullException>(configurationElement != null);

            XmlNamespaceManager nm = Sage.XmlNamespaces.Manager;

            this.Name = configurationElement.GetAttribute("name");
            this.CaseSensitive = !configurationElement.GetAttribute("caseSensitive").ContainsAnyOf("false", "no", "0");

            XmlElement selection = configurationElement.SelectSingleElement("mod:escape", nm);
            if (selection != null)
                this.EscapeChar = selection.InnerText.Trim().Substring(0, 1);

            selection = configurationElement.SelectSingleElement("mod:regexp", nm);
            if (selection != null)
            {
                var pair = selection.InnerText.Trim().Split(' ');
                if (pair.Length == 2)
                {
                    this.RegexStart = pair[0];
                    this.RegexEnd = pair[1];
                }
            }

            foreach (XmlElement commentNode in configurationElement.SelectNodes("mod:comments/mod:linecomment", nm))
                this.LineCommentDelimiters.Add(commentNode.InnerText.Trim());

            foreach (XmlElement commentNode in configurationElement.SelectNodes("mod:comments/mod:comment", nm))
            {
                var pair = commentNode.InnerText.Trim().Split(' ');
                if (pair.Length == 2)
                    this.CommentDelimiters.Add(new Delimiters(pair[0], pair[1]));
            }

            foreach (XmlElement quoteNode in configurationElement.SelectNodes("mod:quotes/mod:quote", nm))
                this.QuoteDelimiters.Add(quoteNode.InnerText.Trim());

            foreach (XmlElement groupNode in configurationElement.SelectNodes("mod:keywords/mod:group", nm))
                this.Expressions.Add(new ExpressionGroup(groupNode, this.CaseSensitive));
        }
开发者ID:igorfrance,项目名称:sage,代码行数:40,代码来源:ModularLanguageDefinition.cs

示例2: ProcessElement

        public ModuleResult ProcessElement(XmlElement moduleElement, ViewConfiguration configuration)
        {
            SageContext context = configuration.Context;
            Initialize(context);

            if (languages.Count == 0)
            {
                log.ErrorFormat("The syntax highligher module isn't configured with any languages. Until this is fixed, the module will not work.");
                return new ModuleResult(ModuleResultStatus.ConfigurationError);
            }

            XmlNode languageNode = moduleElement.SelectSingleNode("mod:config/mod:language", nm);
            XmlElement codeNode = moduleElement.SelectSingleElement("mod:config/mod:code", nm);
            XmlNodeList keywordGroups = moduleElement.SelectNodes("mod:config/mod:keywords/mod:group", nm);
            XmlElement digitsNode = moduleElement.SelectSingleElement("mod:config/mod:digits", nm);

            if (languageNode == null)
                log.ErrorFormat("The required element mod:language is missing from the module configuration");

            if (codeNode == null)
                log.ErrorFormat("The required element mod:code is missing from the module configuration");

            if (languageNode == null || codeNode == null)
                return new ModuleResult(ModuleResultStatus.MissingParameters);

            string language = languageNode.InnerText.Trim();
            string sourceCode = codeNode.InnerText.Trim();
            string sourcePath = codeNode.GetAttribute("src");

            if (string.IsNullOrWhiteSpace(language))
            {
                log.ErrorFormat("The mod:language is missing the required text value");
                return new ModuleResult(ModuleResultStatus.MissingParameters);
            }

            if (!languages.ContainsKey(language))
            {
                log.ErrorFormat("The specified language '{0}' is not recognized. Valid languages are: '{1}'.",
                    language, string.Join(", ", languages.Keys.ToArray()));

                return new ModuleResult(ModuleResultStatus.MissingParameters);
            }

            if (!string.IsNullOrEmpty(sourcePath) && string.IsNullOrWhiteSpace(sourceCode))
            {
                string expanded = context.Path.Resolve(sourcePath);
                if (!File.Exists(expanded))
                {
                    log.ErrorFormat("The specified source code location '{0}' ('{1}') doesn't exist.",
                        sourcePath, expanded);

                    return new ModuleResult(ModuleResultStatus.NoData);
                }

                sourceCode = File.ReadAllText(expanded);
            }

            string indent = null;
            string[] sourceLines = sourceCode.Split('\n');

            foreach (string line in sourceLines)
            {
                Match m;
                if ((m = indentExpr.Match(line)).Success)
                {
                    if (indent == null || m.Groups[1].Value.Length < indent.Length)
                        indent = m.Groups[1].Value;
                }
            }

            if (!string.IsNullOrEmpty(indent))
            {
                StringBuilder trimmed = new StringBuilder();
                Regex cleanup = new Regex("^" + indent);
                foreach (string line in sourceLines)
                {
                    trimmed.AppendLine(cleanup.Replace(line, string.Empty));
                }

                sourceCode = trimmed.ToString();
            }

            List<ExpressionGroup> additionalGroups = new List<ExpressionGroup>();
            if (keywordGroups.Count != 0)
            {
                additionalGroups = new List<ExpressionGroup>();
                foreach (XmlElement keywordElement in keywordGroups)
                {
                    additionalGroups.Add(new ExpressionGroup(keywordElement, languages[language].CaseSensitive));
                }
            }

            SyntaxHighlighter highlighter = new SyntaxHighlighter(languages[language], additionalGroups);
            if (digitsNode != null)
            {
                int lineCountDigits = 0;
                if (int.TryParse(digitsNode.InnerText.Trim(), out lineCountDigits))
                    highlighter.LineCountDigits = lineCountDigits;
            }

//.........这里部分代码省略.........
开发者ID:igorfrance,项目名称:sage,代码行数:101,代码来源:SyntaxHighlighterModule.cs

示例3: InitializeWizardPipeline

    private static void InitializeWizardPipeline(XmlElement element)
    {
      using (new ProfileSection("Initialize wizard pipeline"))
      {
        ProfileSection.Argument("element", element);

        string name1 = element.Name;
        try
        {
          XmlElement argsElement = element.SelectSingleElement("args");
          Type args = argsElement != null
            ? Type.GetType(argsElement.GetAttribute("type")).IsNotNull(
              "Cannot find the {0} type".FormatWith(argsElement.GetAttribute("type")))
            : null;
          XmlElement finish = element.SelectSingleElement("finish");
          string title = element.GetAttribute("title");
          var steps =
            element.SelectSingleElement("steps").IsNotNull(
              "Can't find the steps element in the WizardPipelines.config file").ChildNodes.OfType<XmlElement>().
              Select(
                step =>
                  new StepInfo(step.GetAttribute("name"), Type.GetType(step.GetAttribute("type")),
                    step.GetAttribute("param"))).ToArray();
          string cancelButtonText = element.GetAttribute("cancelButton");
          string startButtonText = element.GetAttribute("startButton");
          string finishText = element.GetAttribute("finishText");
          FinishAction[] finishActions = finish != null ? GetFinishActions(finish, args).ToArray() : null;
          var finishActionHives = GetFinishActionHives(finish, args);
          WizardPipeline wizardPipeline = new WizardPipeline(name1, title, steps, args, startButtonText,
            cancelButtonText, finishText, finishActions,
            finishActionHives);
          Definitions.Add(name1, wizardPipeline);

          ProfileSection.Result("Done");
        }
        catch (Exception ex)
        {
          WindowHelper.HandleError("WizardPipelineManager failed to load the {0} pipeline".FormatWith(name1), true, ex);

          ProfileSection.Result("Failed");
        }
      }
    }
开发者ID:lennartfranke,项目名称:Sitecore-Instance-Manager,代码行数:43,代码来源:WizardPipelineManager.cs

示例4: Parse

        /// <inheritdoc/>
        public void Parse(XmlElement element)
        {
            this.Name = element.GetAttribute("name");
            this.Language = element.GetAttribute("language");

            XmlElement formatElement = element.SelectSingleElement("p:format", XmlNamespaces.Manager);
            try
            {
                culture = new CultureInfo(formatElement.GetAttribute("culture"));
            }
            catch (ArgumentException)
            {
                culture = new CultureInfo(DefaultLocale);
            }

            var shortDate = formatElement.GetAttribute("shortDate");
            var longDate = formatElement.GetAttribute("longDate");

            shortDateFormat = string.IsNullOrEmpty(shortDate) ? "d" : shortDate;
            longDateFormat = string.IsNullOrEmpty(longDate) ? "D" : longDate;

            this.DictionaryNames = new List<string>(element.GetAttribute("dictionaryNames")
                .Replace(" ", string.Empty)
                .Split(',')
                .Distinct());

            this.ResourceNames = new List<string>(element.GetAttribute("resourceNames")
                .Replace(" ", string.Empty)
                .Split(',')
                .Distinct());
        }
开发者ID:igorfrance,项目名称:sage,代码行数:32,代码来源:LocaleInfo.cs

示例5: SynchronizeElements

        private void SynchronizeElements(XmlElement targetElement, XmlElement sourceElement)
        {
            foreach (XmlAttribute attr in sourceElement.Attributes)
            {
                if (targetElement.Attributes[attr.Name] == null)
                    targetElement.SetAttribute(attr.Name, attr.Value);
            }

            foreach (XmlElement sourceChild in sourceElement.SelectNodes("*"))
            {
                XmlNamespaceManager nm = new XmlNamespaceManager(new NameTable());
                nm.AddNamespace("temp", sourceElement.NamespaceURI);

                XmlElement targetChild = targetElement.SelectSingleElement(string.Format("temp:{0}", sourceChild.LocalName), nm);
                if (targetChild == null)
                {
                    targetChild = targetElement.OwnerDocument.CreateElement(sourceChild.Name, sourceChild.NamespaceURI);
                    targetElement.AppendElement(targetElement.OwnerDocument.ImportNode(sourceChild, true));
                }

                this.SynchronizeElements(targetChild, sourceChild);
            }
        }
开发者ID:igorfrance,项目名称:sage,代码行数:23,代码来源:ViewConfiguration.cs

示例6: Parse

        internal void Parse(XmlElement configNode)
        {
            Contract.Requires<ArgumentNullException>(configNode != null);

            this.ValidationResult = ResourceManager.ValidateElement(configNode, ConfigSchemaPath);
            if (!this.ValidationResult.Success)
                return;

            var nm = XmlNamespaces.Manager;
            var packageElement = configNode.SelectSingleNode("p:package", nm);

            this.Type = (ProjectType) Enum.Parse(typeof(ProjectType), configNode.Name, true);
            if (this.Type == ProjectType.Project && packageElement != null)
            {
                this.Type = ProjectType.ExtensionProject;
            }

            foreach (XmlElement child in configNode.SelectNodes(
                string.Format("*[namespace-uri() != '{0}']", XmlNamespaces.ProjectConfigurationNamespace)))
            {
                customElements.Add(child);
            }

            foreach (XmlElement element in configNode.SelectNodes("p:dependencies/p:extension", nm))
            {
                string extensionName = element.GetAttribute("name");
                if (!this.Dependencies.Contains(extensionName))
                    this.Dependencies.Add(extensionName);
            }

            XmlNode variablesNode = configNode.SelectSingleNode("p:variables", nm);
            if (variablesNode != null)
            {
                if (this.VariablesNode != null)
                {
                    foreach (XmlElement variableNode in variablesNode.SelectNodes("*"))
                    {
                        var importReady = this.VariablesNode.OwnerDocument.ImportNode(variableNode, true);
                        var id = variableNode.GetAttribute("id");
                        var current = this.VariablesNode.SelectSingleNode(
                            string.Format("intl:variable[@id='{0}']", id), nm);

                        if (current != null)
                            this.VariablesNode.ReplaceChild(importReady, current);
                        else
                            this.VariablesNode.AppendChild(importReady);
                    }
                }
                else
                {
                    this.VariablesNode = variablesNode;
                }

                this.Variables = new Dictionary<string, NameValueCollection>();

                var variables = variablesNode.SelectNodes("intl:variable", nm);
                foreach (XmlElement elem in variables)
                {
                    var values = elem.SelectNodes("intl:value", nm);
                    var valueDictionary = new NameValueCollection();

                    if (values.Count == 0)
                    {
                        valueDictionary["default"] = elem.InnerText;
                    }
                    else
                    {
                        foreach (XmlElement val in values)
                            valueDictionary.Add(val.GetAttribute("locale"), val.InnerText.Trim());
                    }

                    this.Variables[elem.GetAttribute("id")] = valueDictionary;
                }
            }

            XmlElement routingNode = configNode.SelectSingleElement("p:routing", nm);
            XmlElement pathsNode = configNode.SelectSingleElement("p:paths", nm);

            string nodeValue = configNode.GetAttribute("name");
            if (!string.IsNullOrEmpty(nodeValue))
                this.Name = nodeValue;

            nodeValue = configNode.GetAttribute("sharedCategory");
            if (!string.IsNullOrEmpty(nodeValue))
                this.SharedCategory = nodeValue;

            nodeValue = configNode.GetAttribute("defaultLocale");
            if (!string.IsNullOrEmpty(nodeValue))
                this.DefaultLocale = nodeValue;

            nodeValue = configNode.GetAttribute("defaultCategory");
            if (!string.IsNullOrEmpty(nodeValue))
                this.DefaultCategory = nodeValue;

            nodeValue = configNode.GetAttribute("autoInternationalize");
            if (!string.IsNullOrEmpty(nodeValue))
                this.AutoInternationalize = nodeValue.ContainsAnyOf("yes", "1", "true");

            nodeValue = configNode.GetAttribute("debugMode");
            if (!string.IsNullOrEmpty(nodeValue))
//.........这里部分代码省略.........
开发者ID:igorfrance,项目名称:sage,代码行数:101,代码来源:ProjectConfiguration.cs


注:本文中的System.Xml.XmlElement.SelectSingleElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。