本文整理汇总了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());
}
示例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);
//.........这里部分代码省略.........