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


C# XPathDocument.Evaluate方法代码示例

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


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

示例1: ArgumentContainsSingleResult

        public void ArgumentContainsSingleResult()
        {
            var doc = new XPathDocument("468306.xml");

            var result =
                doc.Evaluate("string(/article[1]/front[1]/article-meta[1]/contrib-group[1]/contrib[1]/name[1]/surname[1])");

            Assert.IsTrue(result is string, "Type was: " + result.GetType().ToString());
        }
开发者ID:bibliopedia,项目名称:bibliopedia,代码行数:9,代码来源:ResourceTests.cs

示例2: Main

        // Methods
        public static int Main(string[] args)
        {
            XPathDocument document;

            ConsoleApplication.WriteBanner();

            OptionCollection options = new OptionCollection {
                new SwitchOption("?", "Show this help page."),
                new StringOption("config", "Specify a configuration file.", "versionCatalog"),
                new StringOption("out", "Specify an output file containing version information.", "outputFile"),
                new BooleanOption("rip", "Specify whether to rip old APIs which are not supported by the " +
                    "latest versions.")
            };

            ParseArgumentsResult result = options.ParseArguments(args);

            if(result.Options["?"].IsPresent)
            {
                Console.WriteLine("VersionBuilder [options]");
                options.WriteOptionSummary(Console.Out);
                return 0;
            }

            if(!result.Success)
            {
                result.WriteParseErrors(Console.Out);
                return 1;
            }

            if(result.UnusedArguments.Count != 0)
            {
                Console.WriteLine("No non-option arguments are supported.");
                return 1;
            }

            if(!result.Options["config"].IsPresent)
            {
                ConsoleApplication.WriteMessage(LogLevel.Error, "You must specify a version catalog file.");
                return 1;
            }

            bool rip = true;

            if(result.Options["rip"].IsPresent && !((bool)result.Options["rip"].Value))
                rip = false;

            string uri = (string)result.Options["config"].Value;

            try
            {
                document = new XPathDocument(uri);
            }
            catch(IOException ioEx)
            {
                ConsoleApplication.WriteMessage(LogLevel.Error, String.Format(CultureInfo.CurrentCulture,
                    "An error occurred while accessing the version catalog file '{0}'. The error message " +
                    "is: {1}", uri, ioEx.Message));
                return 1;
            }
            catch(XmlException xmlEx)
            {
                ConsoleApplication.WriteMessage(LogLevel.Error, String.Format(CultureInfo.CurrentCulture,
                    "The version catalog file '{0}' is not well-formed. The error message is: {1}", uri,
                    xmlEx.Message));
                return 1;
            }

            XPathNavigator navigator = document.CreateNavigator().SelectSingleNode("versions");
            XPathExpression expr = XPathExpression.Compile("string(ancestor::versions/@name)");
            List<VersionInfo> allVersions = new List<VersionInfo>();
            List<string> latestVersions = new List<string>();

            foreach(XPathNavigator navigator2 in document.CreateNavigator().Select("versions//version[@file]"))
            {
                string group = (string)navigator2.Evaluate(expr);
                string attribute = navigator2.GetAttribute("name", String.Empty);

                if(string.IsNullOrEmpty(attribute))
                    ConsoleApplication.WriteMessage(LogLevel.Error, "Every version element must have a name attribute.");

                string name = navigator2.GetAttribute("file", String.Empty);

                if(String.IsNullOrEmpty(attribute))
                    ConsoleApplication.WriteMessage(LogLevel.Error, "Every version element must have a file attribute.");

                string ripOldString = navigator2.GetAttribute("ripOldApis", String.Empty);
                bool ripOld = ripOldString == "1" || String.Equals("true", ripOldString, StringComparison.OrdinalIgnoreCase);

                name = Environment.ExpandEnvironmentVariables(name);
                VersionInfo item = new VersionInfo(attribute, group, name, ripOld);
                allVersions.Add(item);
            }

            string str5 = String.Empty;

            foreach(VersionInfo info2 in allVersions)
                if(!info2.RipOldApis && (!rip || info2.Group != str5))
                {
                    latestVersions.Add(info2.Name);
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:SHFB-1,代码行数:101,代码来源:VersionBuilderCore.cs


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