本文整理汇总了C#中System.Xml.XPath.XPathNavigator.Compile方法的典型用法代码示例。如果您正苦于以下问题:C# XPathNavigator.Compile方法的具体用法?C# XPathNavigator.Compile怎么用?C# XPathNavigator.Compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XPath.XPathNavigator
的用法示例。
在下文中一共展示了XPathNavigator.Compile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EditCand_Load
private void EditCand_Load(object sender, EventArgs e)
{
doc = new XPathDocument(FILE_NAME);
nav = doc.CreateNavigator();
// Compile a standard XPath expression
expr = nav.Compile("/config/voto/@puesto");
iterator = nav.Select(expr);
// Iterate on the node set
comboBox1.Items.Clear();
try
{
while (iterator.MoveNext())
{
XPathNavigator nav2 = iterator.Current.Clone();
comboBox1.Items.Add(nav2.Value);
comboBox1.SelectedIndex = 0;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
//save old title
oldTitle = comboBox1.Text;
}
示例2: GetAttributes
/// <summary>
/// Récupère la valeur de l'attribut du noeud recherché dans le fichier de configuration
/// </summary>
/// <param name="xPathString">Expression XPath de recherche du noeud</param>
/// <param name="attribute">Attribut à rechercher</param>
/// <returns>Une ArrayList contenant la liste des attributs recherchés</returns>
public ArrayList GetAttributes(string xPathString, string attribute)
{
// Initilisation des variables
XPathNodeIterator xpathNodeIterator;
XPathExpression expr;
ArrayList attributes = new ArrayList();
// Parcours du fichier XML
try
{
xpathNavigator = xpathDoc.CreateNavigator();
expr = xpathNavigator.Compile(xPathString);
xpathNodeIterator = xpathNavigator.Select(expr);
while (xpathNodeIterator.MoveNext())
{
// On récupère l'attribut
attributes.Add(xpathNodeIterator.Current.GetAttribute(attribute, ""));
}
}
catch (Exception e)
{
}
return attributes;
}
示例3: GetValue
public string GetValue(string xPathString)
{
xpathNavigator = xpathDoc.CreateNavigator();
XPathExpression expr = xpathNavigator.Compile(xPathString);
XPathNodeIterator xpathNodeIterator = xpathNavigator.Select(expr);
xpathNodeIterator.MoveNext();
return xpathNodeIterator.Current.Value;
}
示例4: Invoke
public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
{
string str = XPathMessageFunction.ToString(args[0]);
string xpath = string.Format(CultureInfo.InvariantCulture, "/s11:Envelope/s11:Header/*[@s11:actor='{0}'] | /s12:Envelope/s12:Header/*[@s12:role='{1}']", new object[] { str, str });
XPathExpression expr = docContext.Compile(xpath);
expr.SetContext((XmlNamespaceManager) xsltContext);
return docContext.Evaluate(expr);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:XPathMessageFunctionHeadersWithActor.cs
示例5: Select
static XPathNodeIterator Select(string expression, XPathNavigator source, params XPathVariable[] variables)
{
var expr = source.Compile(expression);
var context = new DynamicContext();
foreach (var variable in variables)
context.AddVariable(variable.Name, variable.Value);
expr.SetContext(context);
return source.Select(expr);
}
示例6: Invoke
public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
{
if (this.expr == null)
{
XPathExpression expression = docContext.Compile("(sm:header()/wsa10:FaultTo | sm:header()/wsaAugust2004:FaultTo)[1]");
expression.SetContext((XmlNamespaceManager) new XPathMessageContext());
this.expr = expression;
}
return docContext.Evaluate(this.expr);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:10,代码来源:XPathMessageFunctionFaultTo.cs
示例7: Invoke
public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
{
if (this.expr == null)
{
XPathExpression expression = docContext.Compile("(/s11:Envelope/s11:Body | /s12:Envelope/s12:Body)[1]");
expression.SetContext(XPathMessageFunction.Namespaces);
this.expr = expression;
}
return docContext.Evaluate(this.expr);
}
示例8: GetCompiledExpression
/// <summary>
/// Retrieves a cached compiled expression, or a newly compiled one.
/// </summary>
private static XPathExpression GetCompiledExpression(string expression, XPathNavigator source)
{
XPathExpression expr;
if (!Cache.TryGetValue(expression, out expr))
{
// No double checks. At most we will compile twice. No big deal.
expr = source.Compile(expression);
Cache[expression] = expr;
}
return expr.Clone();
}
示例9: Form1_Load
private void Form1_Load(object sender, EventArgs e)
{
String path = @"..\..\..\data\categories.xml";
categories = new XPathDocument(path);
nav = categories.CreateNavigator();
var expr = nav.Compile("//*");
XPathNodeIterator iter = nav.Select(expr);
String category = null;
List<TreeNode> subcats = new List<TreeNode>() ;
while (iter.MoveNext())
{
if(iter.Current.Name == "cat")
{
if(subcats.Count != 0)
{
TreeNode cat_node = new TreeNode(category, subcats.ToArray());
trv_categories.Nodes.Add(cat_node);
subcats.Clear();
}
category = iter.Current.Value;
}
else if(iter.Current.Name == "subcat")
{
subcats.Add(new TreeNode(iter.Current.Value));
}
}
path = @"..\..\..\data\";
synonyms = new Dictionary<string, List<string>>();
StreamReader reader = new StreamReader(path+"synonyms.txt", Encoding.UTF8);
while (!reader.EndOfStream)
{
String line = reader.ReadLine();
if (line.Length <= 0)
continue;
line = line.Trim();
List<String> syms = line.Split(':','،',',').ToList<String>();
for (int i = 0; i < syms.Count; i++)
syms[i] = syms[i].Trim();
String key = syms[0];
syms.RemoveAll(s => s.Length <= 0);
syms.RemoveAt(0);
if (synonyms.ContainsKey(key))
synonyms[key].Concat(syms);
else
synonyms.Add(key, syms);
}
}
示例10: Evaluate
/// <summary>
/// Evaluates an XPath expression in a newly created context, making additional parameters available to the expression.
/// </summary>
/// <param name="nav">
/// Navigator indicating the current node; if <c>null</c>, a dummy navigator is used.
/// </param>
/// <param name="xpathExpr">XPath expression to evaluate.</param>
/// <param name="param">
/// Values to be available while evaluating the expression as <c>$paramN</c>, where N is the
/// index within this array.
/// </param>
/// <returns>The result of evaluating the expression</returns>
public static object Evaluate(XPathNavigator nav, string xpathExpr, params object[] param)
{
Checker.NotNull(xpathExpr, "xpathExpr");
nav = EnsureNavigator(nav);
var expr = nav.Compile(xpathExpr);
var context = new TriflesXPathContext();
int i = 0;
foreach (var paramN in param)
{
context.AddVariable(XNamespace.None + ("param" + i), paramN);
i++;
}
expr.SetContext(context);
return nav.Evaluate(expr);
}
示例11: Invoke
public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
{
if (this.expr == null)
{
XPathExpression e = docContext.Compile("(sm:header()/wsa10:From | sm:header()/wsaAugust2004:From)[1]");
e.SetContext(new XPathMessageContext());
this.expr = e;
}
return docContext.Evaluate(this.expr);
}
示例12: CalculateDrain
private int CalculateDrain(XPathNavigator nav, int force)
{
XPathExpression xprDV;
// Calculate the Spell's Drain for the current Force.
xprDV = nav.Compile(_strDV.Replace("F", force.ToString()).Replace("/", " div "));
decimal decDV = Convert.ToDecimal(nav.Evaluate(xprDV)?.ToString());
decDV = Math.Floor(decDV);
int intDV = Convert.ToInt32(decDV);
// Drain cannot be lower than 2.
if (intDV < 2)
intDV = 2;
return intDV;
}
示例13: PrepareIdNavigator
/// <summary>
/// Prepares the Xpath navigator to improve performance for GetNextId().
/// </summary>
private void PrepareIdNavigator()
{
m_navigator = m_dictionary.CreateNavigator();
m_expression = m_navigator.Compile(m_basePath);
m_expression.AddSort(m_XPathId, XmlSortOrder.Descending, XmlCaseOrder.None, String.Empty, XmlDataType.Number);
}
示例14: UpdateState
//.........这里部分代码省略.........
//Change title
if (name == "FileOrFolderPath" || name == "SearchFor")
{
if (string.IsNullOrWhiteSpace(FileOrFolderPath))
WindowTitle = "dnGREP";
else
WindowTitle = string.Format("{0} in \"{1}\" - dnGREP", (SearchFor == null ? "Empty" : SearchFor.Replace('\n', ' ').Replace('\r', ' ')), FileOrFolderPath);
}
//Change validation
if (name == "SearchFor" || name == "TypeOfSearch")
{
if (string.IsNullOrWhiteSpace(SearchFor))
{
ValidationMessage = "";
}
else if (TypeOfSearch == SearchType.Regex)
{
try
{
Regex regex = new Regex(SearchFor);
ValidationMessage = "Regex is OK!";
}
catch
{
ValidationMessage = "Regex is not valid!";
}
}
else if (TypeOfSearch == SearchType.XPath)
{
try
{
nav = doc.CreateNavigator();
XPathExpression expr = nav.Compile(SearchFor);
ValidationMessage = "XPath is OK!";
}
catch
{
ValidationMessage = "XPath is not valid!";
}
}
else
{
ValidationMessage = "";
}
}
//Can search
if (name == "FileOrFolderPath" || name == "CurrentGrepOperation" || name == "SearchFor")
{
if (Utils.IsPathValid(FileOrFolderPath) && CurrentGrepOperation == GrepOperation.None &&
(!string.IsNullOrEmpty(SearchFor) || settings.Get<bool>(GrepSettings.Key.AllowSearchingForFileNamePattern)))
{
CanSearch = true;
}
else
{
CanSearch = false;
}
// Refersh buttons
CommandManager.InvalidateRequerySuggested();
}
//Set all files if FileOrFolderPath is a file
if (name == "FileOrFolderPath")
{
示例15: CreateIterator
private XPathNodeIterator CreateIterator(string queryString, XPathNavigator nav)
{
XPathExpression query = nav.Compile(queryString);
XPathNodeIterator iter = nav.Select(query);
return iter;
}