/// <summary>
 /// Returns the string result from evaluating an xpath expression against the given document and
 /// context created from key/value pairs.
 /// </summary>
 /// <example>
 /// string result = BuildComponentUtilities.EvalXPathExpr(doc, "concat($key, '.htm')", "key", "file");
 /// </example>
 public static string EvalXPathExpr(IXPathNavigable doc, XPathExpression xpe, params string[] keyValuePairs) {
     Debug.Assert(keyValuePairs.Length % 2 == 0);
     CustomContext cc = new CustomContext();
     for (int i = 0; i < keyValuePairs.Length; i += 2)
         cc[keyValuePairs[i]] = keyValuePairs[i + 1];
     return EvalXPathExpr(doc, xpe, cc);
 }
 /// <summary>
 /// Returns the string result from evaluating an xpath expression against the given document and context.
 /// </summary>
 public static string EvalXPathExpr(IXPathNavigable doc, XPathExpression xpe, CustomContext c) {
     XPathExpression t = xpe.Clone();
     t.SetContext(c);
     return doc.CreateNavigator().Evaluate(t).ToString();
 }
        public TargetInfo GetTargetInfo (XPathNavigator linkNode, CustomContext context) {

            // compute the metadata file name to open
            XPathExpression localFileExpression = fileExpression.Clone();
            localFileExpression.SetContext(context);
            string file = linkNode.Evaluate(localFileExpression).ToString();
            if (String.IsNullOrEmpty(file)) return (null);

            // load the metadata file
            XPathDocument metadataDocument = GetDocument(file);
            if (metadataDocument == null) return (null);

            // querry the metadata file for the target url and link text
            XPathNavigator metadataNode = metadataDocument.CreateNavigator();
            XPathExpression localUrlExpression = urlExpression.Clone();
            localUrlExpression.SetContext(context);
            string url = metadataNode.Evaluate(localUrlExpression).ToString();
            XPathExpression localTextExpression = textExpression.Clone();
            localTextExpression.SetContext(context);
            string text = metadataNode.Evaluate(localTextExpression).ToString();

            // return this information
            TargetInfo info = new TargetInfo(url, text, type);
            return (info);
        }
 public TargetInfo GetTargetInfo (XPathNavigator linkNode, CustomContext context) {
     foreach (TargetDirectory targetDirectory in targetDirectories) {
         TargetInfo info = targetDirectory.GetTargetInfo(linkNode, context);
         if (info != null) return (info);
     }
     return (null);
 }
		private static CustomContext GetContext (XPathNavigator configuration) {

			CustomContext context = new CustomContext();

			XPathNodeIterator context_nodes = configuration.Select("context");
			foreach (XPathNavigator context_node in context_nodes) {
				string prefix = context_node.GetAttribute("prefix", String.Empty);
				string name = context_node.GetAttribute("name", String.Empty);
				context.AddNamespace(prefix, name);
			}

			return(context);			

		}