示例#1
0
		public XslSortEvaluator (XPathExpression select, Sort [] sorterTemplates)
		{
			this.select = select;
			this.sorterTemplates = sorterTemplates;
			PopulateConstantSorters ();
			sortRunner = new XPathSorters ();
		}
示例#2
0
        /// <summary>
        /// Override method that performs the actual property setting from a boolean result.
        /// </summary>
        /// <param name="component"></param>
        /// <param name="data"></param>
        /// <param name="context"></param>
        protected override void DoBindComponent(object component, object data, PDFDataContext context)
        {
            System.Xml.XPath.XPathExpression   expr = this.GetExpression(data, context);
            System.Xml.XPath.XPathNavigator    nav;
            System.Xml.XPath.XPathNodeIterator itter;

            if (data is System.Xml.XPath.XPathNodeIterator)
            {
                itter = ((System.Xml.XPath.XPathNodeIterator)data);
                nav   = itter.Current;
            }
            else
            {
                nav   = (System.Xml.XPath.XPathNavigator)data;
                itter = context.DataStack.HasData ? context.DataStack.Current as System.Xml.XPath.XPathNodeIterator : null;
            }

            bool value = (bool)nav.Evaluate(expr, itter);

            if (context.ShouldLogVerbose)
            {
                context.TraceLog.Add(TraceLevel.Verbose, "Item Binding", "Setting property '" + this.Property.Name + "' with the XPath binding expression '" + expr.Expression + "' to value '" + value + "'");
            }

            this.Property.SetValue(component, value, null);
        }
示例#3
0
        //=====================================================================

        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            // Get the condition
            XPathNavigator if_node = configuration.SelectSingleNode("if");

            if(if_node == null)
                throw new ConfigurationErrorsException("You must specify a condition using the <if> element.");

            string condition_xpath = if_node.GetAttribute("condition", String.Empty);

            if(String.IsNullOrEmpty(condition_xpath))
                throw new ConfigurationErrorsException("You must define a condition attribute on the <if> element");

            condition = XPathExpression.Compile(condition_xpath);

            // Construct the true branch
            XPathNavigator then_node = configuration.SelectSingleNode("then");

            if(then_node != null)
                true_branch = BuildAssembler.LoadComponents(then_node);

            // Construct the false branch
            XPathNavigator else_node = configuration.SelectSingleNode("else");

            if(else_node != null)
                false_branch = BuildAssembler.LoadComponents(else_node);

            // Keep a pointer to the context for future use
            context = this.BuildAssembler.Context;
        }
示例#4
0
		public SaveComponent (BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) {

			// load the target path format
			XPathNavigator save_node = configuration.SelectSingleNode("save");
			if (save_node == null) throw new ConfigurationErrorsException("When instantiating a save component, you must specify a the target file using the <save> element.");

			string base_value = save_node.GetAttribute("base", String.Empty);
			if (!String.IsNullOrEmpty(base_value)) {
				basePath = Path.GetFullPath(Environment.ExpandEnvironmentVariables(base_value));
			}

			string path_value = save_node.GetAttribute("path", String.Empty);
			if (String.IsNullOrEmpty(path_value)) WriteMessage(MessageLevel.Error, "Each save element must have a path attribute specifying an XPath that evaluates to the location to save the file.");
			path_expression = XPathExpression.Compile(path_value);

            string select_value = save_node.GetAttribute("select", String.Empty);
            if (!String.IsNullOrEmpty(select_value))
                select_expression = XPathExpression.Compile(select_value);

            settings.Encoding = Encoding.UTF8;

			string indent_value = save_node.GetAttribute("indent", String.Empty);
			if (!String.IsNullOrEmpty(indent_value)) settings.Indent = Convert.ToBoolean(indent_value);

			string omit_value = save_node.GetAttribute("omit-xml-declaration", String.Empty);
			if (!String.IsNullOrEmpty(omit_value)) settings.OmitXmlDeclaration = Convert.ToBoolean(omit_value);

            linkPath = save_node.GetAttribute("link", String.Empty);
            if (String.IsNullOrEmpty(linkPath)) linkPath = "../html";

			// encoding

			settings.CloseOutput = true;

		}
		protected override void Compile (Compiler c)
		{
			if (c.Debugger != null)
				c.Debugger.DebugCompile (this.DebugInput);

			c.CheckExtraAttributes ("value-of", "select", "disable-output-escaping");

			c.AssertAttribute ("select");
			select = c.CompileExpression (c.GetAttribute ("select"));
			disableOutputEscaping = c.ParseYesNoAttribute ("disable-output-escaping", false);
			if (c.Input.MoveToFirstChild ()) {
				do {
					switch (c.Input.NodeType) {
					case XPathNodeType.Element:
						if (c.Input.NamespaceURI == XsltNamespace)
							goto case XPathNodeType.SignificantWhitespace;
						// otherwise element in external namespace -> ignore
						break;
					case XPathNodeType.Text:
					case XPathNodeType.SignificantWhitespace:
						throw new XsltCompileException ("XSLT value-of element cannot contain any child.", null, c.Input);
					}
				} while (c.Input.MoveToNext ());
			}
		}
示例#6
0
        //=====================================================================

        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            // get the condition
            XPathNavigator condition_element = configuration.SelectSingleNode("switch");

            if(condition_element == null)
                throw new ConfigurationErrorsException("You must specify a condition using the <switch> statement with a 'value' attribute.");

            string condition_value = condition_element.GetAttribute("value", String.Empty);

            if(String.IsNullOrEmpty(condition_value))
                throw new ConfigurationErrorsException("The switch statement must have a 'value' attribute, which is an xpath expression.");

            condition = XPathExpression.Compile(condition_value);

            // load the component stacks for each case
            XPathNodeIterator case_elements = configuration.Select("case");

            foreach(XPathNavigator case_element in case_elements)
            {
                string case_value = case_element.GetAttribute("value", String.Empty);

                cases.Add(case_value, BuildAssembler.LoadComponents(case_element));
            }
        }
示例#7
0
		/// <summary>
		/// Implements the following function
		/// node-set exsl:node-set(object)
		/// </summary>
		/// <param name="o"></param>
		/// <returns></returns>        
        public XPathNodeIterator nodeSet(object o) 
        {		
            if (o is XPathNavigator) 
            {
                XPathNavigator nav = (XPathNavigator)o;		        
                if (selectItself == null)
                    selectItself = nav.Compile(".");                                    
                return nav.Select(selectItself.Clone());
            } 
            else if (o is XPathNodeIterator)
                return o as XPathNodeIterator;
            else 
            {
                string s;
                if (o is string) 
                    s = o as string;
                else if (o is bool)
                    s = ((bool)o)? "true" : "false";
                else if (o is Double || o is Int16 || o is UInt16 || o is Int32
                    || o is UInt32 || o is Int64 || o is UInt64 || o is Single || o is Decimal)    
                    s = o.ToString();
                else    
                    return null;	
                //Now convert it to text node
                XmlParserContext context = new XmlParserContext(null, null, null, XmlSpace.None);                				    			
                XPathDocument doc = new XPathDocument(
                    new XmlTextReader("<d>"+s+"</d>", XmlNodeType.Element, context));				
                XPathNavigator nav = doc.CreateNavigator();                                         
                if (selectText == null)
                    selectText = nav.Compile("/d/text()");
                return nav.Select(selectText.Clone());
            }
        }
		private void AddTargets (string map, string input, string baseOutputPath, XPathExpression outputXPath, string link, XPathExpression formatXPath, XPathExpression relativeToXPath) {

			XPathDocument document = new XPathDocument(map);

			XPathNodeIterator items = document.CreateNavigator().Select("/*/item");
			foreach (XPathNavigator item in items) {

				string id = (string) item.Evaluate(artIdExpression);
				string file = (string) item.Evaluate(artFileExpression);
				string text = (string) item.Evaluate(artTextExpression);

				id = id.ToLower();
				string name = Path.GetFileName(file);

				ArtTarget target = new ArtTarget();
				target.Id = id;
				target.InputPath = Path.Combine(input, file);
				target.baseOutputPath = baseOutputPath;
                target.OutputXPath = outputXPath;
                
                if (string.IsNullOrEmpty(name)) target.LinkPath = link;
                else target.LinkPath = string.Format("{0}/{1}", link, name);
                
				target.Text = text;
                target.Name = name;
                target.FormatXPath = formatXPath;
                target.RelativeToXPath = relativeToXPath;

				targets[id] = target;
				// targets.Add(id, target);
            }

	    }
        public override XPathNodeIterator Select(XPathExpression expr)
        {
            if (Queryables.ContainsKey(expr.Expression))
                return new XPathQueryableIterator(Queryables[expr.Expression]);

            return base.Select(expr);
        }
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="path">The path expression</param>
        /// <param name="item">The item name expression</param>
        /// <param name="parameters">The parameters expression</param>
        /// <param name="attribute">The attribute name expression</param>
        /// <param name="context">The context to use for the XPath expressions</param>
        public SharedContentElement(string path, string item, string parameters, string attribute,
          IXmlNamespaceResolver context)
        {
            this.Path = XPathExpression.Compile(path, context);
            this.Item = XPathExpression.Compile(item, context);
            this.Parameters = XPathExpression.Compile(parameters, context);
            this.Attribute = XPathExpression.Compile(attribute, context);
        }
        static CfgXmlHelper()
        {
            NameTable nt = new NameTable();
            nsMgr = new XmlNamespaceManager(nt);
            nsMgr.AddNamespace(CfgNamespacePrefix, CfgSchemaXMLNS);

            SearchFactoryExpression = XPathExpression.Compile(RootPrefixPath + ":search-factory", nsMgr);
        }
示例#12
0
 public XPathSelectionIterator(XPathNavigator nav, XPathExpression expr) {
     this.nav = nav.Clone();
     query = ((CompiledXpathExpr) expr).QueryTree;
     if (query.ReturnType() != XPathResultType.NodeSet) {
         throw new XPathException(Res.Xp_NodeSetExpected);
     }
     query.setContext(nav.Clone());
 }
示例#13
0
        public static System.Xml.XPath.XPathNodeIterator EvaluateSelectExpression(System.Xml.XPath.XPathExpression expr, PDFDataContext context)
        {
            throw new NotSupportedException("No Longer using the XPathDataHelper");

            //if (null == expr)
            //    throw new ArgumentNullException("expr");
            //if (null == context)
            //    throw new ArgumentNullException("context");
            //if (false == context.DataStack.HasData)
            //    throw new ArgumentOutOfRangeException("context.DataStack.Current");
            //if (null == context.DataStack.Current)
            //    throw new ArgumentNullException("context.DataStack.Current");

            //object currentData = context.DataStack.Pop();
            //System.Xml.XPath.XPathNodeIterator itter;



            //try
            //{
            //    //Need the current data to be an XPathNavigator
            //    System.Xml.XPath.XPathNavigator navigator;
            //    if (currentData is System.Xml.XPath.XPathNavigator)
            //    {
            //        navigator = currentData as System.Xml.XPath.XPathNavigator;
            //    }
            //    else if (currentData is System.Xml.XPath.IXPathNavigable)
            //    {
            //        System.Xml.XPath.IXPathNavigable nav = (System.Xml.XPath.IXPathNavigable)currentData;
            //        navigator = nav.CreateNavigator();
            //    }
            //    else
            //        throw new InvalidCastException(Errors.DatabindingSourceNotXPath);

            //    // For position() and data context relative functions we also need to provide the
            //    // iterator the current XPathNavigator we extracted from if available.

            //    System.Xml.XPath.XPathNodeIterator parentItterator;

            //    if (context.DataStack.HasData && context.DataStack.Current is System.Xml.XPath.XPathNodeIterator)
            //        parentItterator = context.DataStack.Current as System.Xml.XPath.XPathNodeIterator;
            //    else
            //        parentItterator = null;

            //    if (null != context.NamespaceResolver)
            //        expr.SetContext(context.NamespaceResolver);

            //    itter = navigator.Select(expr);
            //}
            //finally
            //{
            //    //make sure we put the stack back to the original state.

            //    context.DataStack.Push(currentData, null);
            //}

            //return itter;
        }
示例#14
0
        static XmlHelper()
        {
            NameTable nt = new NameTable();
            XmlNamespaceManager nsMgr = new XmlNamespaceManager(nt);
            nsMgr.AddNamespace(NamespacePrefix, SchemaXmlns);

            PropertiesExpression = XPathExpression.Compile(RootPrefixPath + "properties", nsMgr);
            PropertiesPropertyExpression = XPathExpression.Compile(RootPrefixPath + "properties/" + ChildPrefixPath + "property", nsMgr);
        }
        static CfgXmlHelper()
        {
            NameTable nt = new NameTable();
            nsMgr = new XmlNamespaceManager(nt);
            nsMgr.AddNamespace(CfgNamespacePrefix, CfgSchemaXMLNS);

            SharedEngineClassExpression = XPathExpression.Compile(RootPrefixPath + Environment.SharedEngineClass, nsMgr);
            PropertiesExpression = XPathExpression.Compile(RootPrefixPath + "property", nsMgr);
            MappingsExpression = XPathExpression.Compile(RootPrefixPath + "mapping", nsMgr);
        }
 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);
 }
示例#17
0
		protected override void Compile (Compiler c)
		{
			if (c.Debugger != null)
				c.Debugger.DebugCompile (c.Input);

			c.CheckExtraAttributes ("copy-of", "select");

			c.AssertAttribute ("select");
			select = c.CompileExpression (c.GetAttribute ("select"));
		}
 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);
 }
        /// <summary>
        /// This method returns an instance of <see cref="XPathQueryManagerCompiledExpressionsDecorator"/> 
        /// in the context of the first node the XPath expression addresses.
        /// </summary>
        /// <param name="xPath">The compiled XPath expression</param>
        /// <param name="queryParameters">Parameters for the compiled XPath expression</param>
        public override IXPathQueryManager GetXPathQueryManagerInContext(XPathExpression xPath,
                                                                         DictionaryEntry[] queryParameters = null)
        {
            IXPathQueryManager xPathQueryManager = (queryParameters == null)
                                                       ? XPathQueryManager.GetXPathQueryManagerInContext(xPath)
                                                       : XPathQueryManager.GetXPathQueryManagerInContext(xPath,
                                                                                                          queryParameters);

            if (xPathQueryManager == null) return null;
            return new XPathQueryManagerCompiledExpressionsDecorator(xPathQueryManager);
        }
		public void CoreFunctionNodeSetLast ()
		{
			expression = navigator.Compile("last()");
			iterator = navigator.Select("/foo");
			AssertEquals ("0", navigator.Evaluate ("last()").ToString());
			AssertEquals ("0", navigator.Evaluate (expression, null).ToString ());
			AssertEquals ("1", navigator.Evaluate (expression, iterator).ToString ());
			iterator = navigator.Select("/foo/*");
			AssertEquals ("4", navigator.Evaluate (expression, iterator).ToString ());
			
			AssertEquals("3", navigator2.Evaluate ("string(//bar[last()]/@baz)"));
		}
        static XmlSchemaParser()
        {
            XPathNavigator nav = new XmlDocument().CreateNavigator();
            // Select all extension types.
            Extensions = nav.Compile( "/xs:schema/xs:annotation/xs:appinfo/kzu:Code/kzu:Extension/@Type" );

            // Create and set namespace resolution context.
            XmlNamespaceManager nsmgr = new XmlNamespaceManager( nav.NameTable );
            nsmgr.AddNamespace( "xs", XmlSchema.Namespace );
            nsmgr.AddNamespace( "kzu", ExtensionNamespace );
            Extensions.SetContext( nsmgr );
        }
示例#22
0
 static Processor()
 {
     XPathNavigator nav = new XmlDocument().CreateNavigator();
     // Select all extension types.
     Extensions = nav.Compile("/processing-instruction('extension')");
     PostExts = nav.Compile("/processing-instruction('post-process')");
     // Create and set namespace resolution context.
     XmlNamespaceManager nsmgr = new XmlNamespaceManager(nav.NameTable);
     nsmgr.AddNamespace("xs", XmlSchema.Namespace);
     nsmgr.AddNamespace("kzu", ExtensionNamespace);
     Extensions.SetContext(nsmgr);
 }
        /// <summary>
        /// Selects a node set, using the specified XPath expression.
        /// </summary>
        /// <param name="navigator">A source XPathNavigator.</param>
        /// <param name="expression">An XPath expression.</param>
        /// <param name="variables">A set of XPathVariables.</param>
        /// <returns>An iterator over the nodes matching the specified expression.</returns>
        public static XPathNodeIterator Select(this XPathNavigator navigator, XPathExpression expression, params XPathVariable[] variables)
        {
            if (variables == null || variables.Length == 0 || variables[0] == null)
                return navigator.Select(expression);

            var compiled = expression.Clone(); // clone for thread-safety
            var context = new DynamicContext();
            foreach (var variable in variables)
                context.AddVariable(variable.Name, variable.Value);
            compiled.SetContext(context);
            return navigator.Select(compiled);
        }
        public override bool Match(MessageBuffer buffer)
        {
            if (_filterExpression == null)
            {
                _filterExpression = XPathExpression.Compile($"////value == {_filterParam}");
            }

            XPathNavigator navigator = buffer.CreateNavigator();
            return navigator.Matches(_filterExpression);
            //XDocument doc = await GetMessageEnvelope(buffer);
            //return Match(doc);
        }
示例#25
0
		protected override void Compile (Compiler c)
		{
			if (c.Debugger != null)
				c.Debugger.DebugCompile (c.Input);

			c.CheckExtraAttributes ("apply-templates", "select", "mode");

			select = c.CompileExpression (c.GetAttribute ("select"));
			mode = c.ParseQNameAttribute ("mode");
			ArrayList sorterList = null;
			if (c.Input.MoveToFirstChild ()) {
				do {
					switch (c.Input.NodeType) {
					case XPathNodeType.Comment:
					case XPathNodeType.ProcessingInstruction:
					case XPathNodeType.Whitespace:
					case XPathNodeType.SignificantWhitespace:
						continue;
					case XPathNodeType.Element:
						if (c.Input.NamespaceURI != XsltNamespace)
							throw new XsltCompileException ("Unexpected element", null, c.Input); // TODO: fwd compat
						
						switch (c.Input.LocalName)
						{
							case "with-param":
								if (withParams == null)
									withParams = new ArrayList ();
								withParams.Add (new XslVariableInformation (c));
								break;
								
							case "sort":
								if (sorterList == null)
									sorterList = new ArrayList ();
								if (select == null)
									select = c.CompileExpression ("*");
								sorterList.Add (new Sort (c));
								//c.AddSort (select, new Sort (c));
								break;
							default:
								throw new XsltCompileException ("Unexpected element", null, c.Input); // todo forwards compat
						}
						break;
					default:
						throw new XsltCompileException ("Unexpected node type " + c.Input.NodeType, null, c.Input);	// todo forwards compat
					}
				} while (c.Input.MoveToNext ());
				c.Input.MoveToParent ();
			}
			if (sorterList != null)
				sortEvaluator = new XslSortEvaluator (select,
					(Sort []) sorterList.ToArray (typeof (Sort)));
		}
示例#26
0
        //
        // support methods
        //

        #region protected System.Xml.XPath.XPathExpression GetExpression(object data, PDFDataContext context)

        /// <summary>
        /// Converts the string expression on this instance to an actual XPathExpression with the current context
        /// </summary>
        /// <param name="data">The current data object on the stack</param>
        /// <param name="context">The current data context</param>
        /// <returns>A prepared XPath expression</returns>
        protected System.Xml.XPath.XPathExpression GetExpression(object data, PDFDataContext context)
        {
            if (null == _compiled)
            {
                _compiled = System.Xml.XPath.XPathExpression.Compile(this._expr, context.NamespaceResolver);
            }
            else
            {
                _compiled.SetContext(context.NamespaceResolver);
            }

            return(_compiled);
        }
示例#27
0
        public static bool EvaluateTestExpression(System.Xml.XPath.XPathExpression expr, PDFDataContext context)
        {
            throw new NotSupportedException("No Longer using the XPathDataHelper");

            //object value = EvaluateValueExpression(expr, context);

            //if (null == value)
            //    return false;
            //else if (value is bool)
            //    return (bool)value;
            //else
            //    return false;
        }
		private static void SelectIndexedNodes(XPathNavigator nav, int repeat, PerfTest perf, XPathExpression expr) 
		{
			int counter = 0;
			perf.Start();
			for (int i=0; i<repeat; i++) 
			{
				XPathNodeIterator ni =  nav.Select(expr);
				while (ni.MoveNext())
					counter++;
			}
			Console.WriteLine("Indexed selection: {0} times, total time {1, 6:f2} ms, {2} nodes selected", repeat, 
				perf.Stop(), counter);
		}
示例#29
0
文件: Binding.cs 项目: nxkit/nxkit
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="xml"></param>
        /// <param name="context"></param>
        /// <param name="xpath"></param>
        internal Binding(XObject xml, EvaluationContext context, XPathExpression xpath)
        {
            Contract.Requires<ArgumentNullException>(xml != null);
            Contract.Requires<ArgumentNullException>(context != null);
            Contract.Requires<ArgumentNullException>(xpath != null);

            this.xml = xml;
            this.context = context;
            this.xpath = xpath;

            // initial load of values
            Recalculate();
        }
示例#30
0
        /// <summary>
        /// Override method that performs the actual property setting from a nodeset result.
        /// </summary>
        /// <param name="component"></param>
        /// <param name="data"></param>
        /// <param name="context"></param>
        protected override void DoBindComponent(object component, object data, PDFDataContext context)
        {
            System.Xml.XPath.XPathExpression expr = this.GetExpression(data, context);

            if (data is System.Xml.XPath.XPathNodeIterator)
            {
                data = ((System.Xml.XPath.XPathNodeIterator)data).Current;
            }

            XPathNavigator nav = (System.Xml.XPath.XPathNavigator)data;

            if (null == this.Converter)
            {
                var iterator = nav.Select(expr);

                if (this.Property.PropertyType == typeof(XPathNavigator))
                {
                    this.Property.SetValue(component, iterator.Current);
                }
                else
                {
                    this.Property.SetValue(component, iterator);
                }
            }
            else
            {
                nav = nav.SelectSingleNode(expr);

                if (null != nav)
                {
                    string result = nav.Value;

                    if (context.ShouldLogVerbose)
                    {
                        context.TraceLog.Add(TraceLevel.Verbose, "Item Binding", "Setting property '" + this.Property.Name + "' with the XPath binding expression '" + expr.Expression + "' to value '" + result + "'");
                    }

                    SetToConvertedValue(component, result, context);
                }
                else
                {
                    if (context.ShouldLogVerbose)
                    {
                        context.TraceLog.Add(TraceLevel.Verbose, "Item Binding", "NULL value returned for expression '" + expr.Expression + "' so clearing property value '" + this.Property.Name + "'");
                    }
                    SetToEmptyValue(component, context);
                }
            }
        }
示例#31
0
        public PluginUI(PluginMain pluginMain)
        {
            this.InitializeComponent();
            this.imagelist = new ImageList();
            this.imagelist.Images.Add(GetResource("Icons.ActionClosed.png"));
            this.imagelist.Images.Add(GetResource("Icons.ActionOpened.png"));
            this.imagelist.Images.Add(GetResource("Icons.ActionFunction.png"));

            this.Documents = null;
            this.treeView1.ImageList = this.imagelist;
            this.pluginMain = pluginMain;

            xpathExpression_1 = XPathExpression.Compile("folder|ifdef/folder|ifmode/folder");
            xpathExpression_2 = XPathExpression.Compile("string|ifdef/string|ifmode/string|action|ifmode/action|ifdef/action");
        }
		private static void SelectNodes(XPathNavigator nav, int repeat, Stopwatch stopWatch, XPathExpression expr) 
		{
			int counter = 0;
            stopWatch.Start();
			for (int i=0; i<repeat; i++) 
			{
				XPathNodeIterator ni =  nav.Select(expr);
				while (ni.MoveNext())
					counter++;
			}
            stopWatch.Stop();
			Console.WriteLine("Regular selection: {0} times, total time {1, 6:f2} ms, {2} nodes selected", repeat,
                stopWatch.ElapsedMilliseconds, counter);
            stopWatch.Reset();
		}
示例#33
0
        //
        // factory methods
        //

        #region public static BindingXPathExpression Create(string expr, PDFValueConverter convert, System.Reflection.PropertyInfo property)

        /// <summary>
        /// Returns a new concrete instance of a BindingXPathExpression that can be called from a components
        /// DataBinding event and set the value of the property.
        /// </summary>
        /// <param name="expr">The binding XPath expression to use</param>
        /// <param name="convert">A value converter to change the string result into the required type.</param>
        /// <param name="property">The property this expression is bound to.</param>
        /// <returns>The expression that ban be attached to an event</returns>
        public static BindingXPathExpression Create(string expr, PDFValueConverter convert, System.Reflection.PropertyInfo property)
        {
            if (null == property)
            {
                throw new ArgumentNullException("property");
            }
            if (string.IsNullOrEmpty(expr))
            {
                throw new ArgumentNullException("expr");
            }

            //Run a quick compile to validat the return type
            System.Xml.XPath.XPathExpression compiled = System.Xml.XPath.XPathExpression.Compile(expr);
            BindingXPathExpression           binding  = null;

            switch (compiled.ReturnType)
            {
            case System.Xml.XPath.XPathResultType.Boolean:
                binding = new BindingXPathBoolExpression();
                break;

            case System.Xml.XPath.XPathResultType.NodeSet:
                binding = new BindingXPathNodeSetExpression();
                break;

            case System.Xml.XPath.XPathResultType.Number:
            case System.Xml.XPath.XPathResultType.String:
                binding = new BindingXPathValueExpression();
                break;

            case System.Xml.XPath.XPathResultType.Error:
                throw new PDFParserException(String.Format(Errors.InvalidXPathExpression, expr));

            case System.Xml.XPath.XPathResultType.Any:
            default:
                throw new PDFParserException(String.Format(Errors.ReturnTypeOfXPathExpressionCouldNotBeDetermined, expr));
            }

            binding._converter = convert;
            binding._expr      = expr;
            binding._compiled  = compiled;
            binding._property  = property;

            return(binding);
        }
示例#34
0
        /// <summary>
        /// Override method that performs the actual property setting from a Navigator result.
        /// </summary>
        /// <param name="component"></param>
        /// <param name="data"></param>
        /// <param name="context"></param>
        protected override void DoBindComponent(object component, object data, PDFDataContext context)
        {
            System.Xml.XPath.XPathExpression expr = this.GetExpression(data, context);

            if (data is System.Xml.XPath.XPathNodeIterator)
            {
                data = ((System.Xml.XPath.XPathNodeIterator)data).Current;
            }

            System.Xml.XPath.XPathNavigator nav = (System.Xml.XPath.XPathNavigator)data;

            if (null == this.Converter)
            {
                var iterator = nav.Select(expr);

                if (this.Property.PropertyType == typeof(XPathNavigator))
                {
                    this.Property.SetValue(component, iterator.Current);
                }
                else
                {
                    this.Property.SetValue(component, iterator);
                }
            }
            else
            {
                System.Xml.XPath.XPathNodeIterator itter = nav.Select(expr);

                if (itter.CurrentPosition < 0)
                {
                    itter.MoveNext();
                }

                string value     = itter.Current.Value;
                object converted = this.Converter(value, this.Property.PropertyType, System.Globalization.CultureInfo.CurrentCulture);


                if (context.ShouldLogVerbose)
                {
                    context.TraceLog.Add(TraceLevel.Verbose, "Item Binding", "Setting property '" + this.Property.Name + "' with the XPath binding expression '" + expr.Expression + "' to value '" + ((null == value) ? "NULL" : value) + "'");
                }

                this.Property.SetValue(component, converted, null);
            }
        }
示例#35
0
        /// <summary>
        /// Override method that performs the actual property setting from a value result.
        /// </summary>
        /// <param name="component"></param>
        /// <param name="data"></param>
        /// <param name="context"></param>
        protected override void DoBindComponent(object component, object data, PDFDataContext context)
        {
            System.Xml.XPath.XPathExpression expr = this.GetExpression(data, context);

            System.Xml.XPath.XPathNavigator    nav;
            System.Xml.XPath.XPathNodeIterator itter;

            if (data is System.Xml.XPath.XPathNodeIterator)
            {
                itter = ((System.Xml.XPath.XPathNodeIterator)data);
                nav   = itter.Current;
            }
            else
            {
                nav   = (System.Xml.XPath.XPathNavigator)data;
                itter = context.DataStack.HasData ? context.DataStack.Current as System.Xml.XPath.XPathNodeIterator : null;
            }


            object value = nav.Evaluate(expr, itter);

            if (null != value)
            {
                string result = value.ToString();

                if (context.ShouldLogVerbose)
                {
                    context.TraceLog.Add(TraceLevel.Verbose, "Item Binding", "Setting property '" + this.Property.Name + "' with the XPath binding expression '" + expr.Expression + "' to value '" + result + "'");
                }

                SetToConvertedValue(component, result, context);
            }
            else
            {
                if (context.ShouldLogVerbose)
                {
                    context.TraceLog.Add(TraceLevel.Verbose, "Item Binding", "NULL value returned for expression '" + expr.Expression + "' so clearing value '" + this.Property.Name + "'");
                }
                SetToEmptyValue(component, context);
            }
        }
示例#36
0
 /// <include file='doc\XPathNavigator.uex' path='docs/doc[@for="XPathNavigator.Evaluate"]/*' />
 public virtual object Evaluate(XPathExpression expr)
 {
     return(Evaluate(expr, null));
 }
示例#37
0
 /// <include file='doc\XPathNavigator.uex' path='docs/doc[@for="XPathNavigator.Select"]/*' />
 public virtual XPathNodeIterator Select(XPathExpression expr)
 {
     return(new XPathSelectionIterator(this, expr));
 }
示例#38
-1
 public static void Init()
 {
     NameTable nt = new NameTable();
     XmlNamespaceManager NsMgr = new XmlNamespaceManager(nt);
     NsMgr.AddNamespace(XmlConstants.Namespace, XmlConstants.SchemaXMLNS);
     ConfigExpression = XPathExpression.Compile("//" + XmlConstants.Namespace + ":" + XmlConstants.Setting, NsMgr);
 }
        public LiveExampleComponent(BuildAssembler assembler, XPathNavigator configuration)
            : base(assembler, configuration) {

            XPathNavigator parsnip_node = configuration.SelectSingleNode("parsnip");
            string approvedFile = null;
            if (parsnip_node != null) {
                approvedFile = parsnip_node.GetAttribute("approved-file", String.Empty);

                string omitBadExamplesValue = parsnip_node.GetAttribute("omit-bad-examples", String.Empty);
                if (!string.IsNullOrEmpty(omitBadExamplesValue))
                    omitBadExamples = Boolean.Parse(omitBadExamplesValue);

                //string runBadExamplesValue = parsnip_node.GetAttribute("run-bad-examples", String.Empty);
                //if (!string.IsNullOrEmpty(runBadExamplesValue))
                //    runBadExamples = Boolean.Parse(runBadExamplesValue);
            }

            if (string.IsNullOrEmpty(approvedFile))
                WriteMessage(MessageLevel.Warn, "No approved samples file specified; all available samples will be included.");
            else
                LoadApprovedFile(approvedFile);

            context = new CustomContext();
            context.AddNamespace("ddue", "http://ddue.schemas.microsoft.com/authoring/2003/5");

            selector = XPathExpression.Compile("//ddue:codeReference");
            selector.SetContext(context);
        }
示例#40
-3
文件: EditCand.cs 项目: ayeec/evote
        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;

        }