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


C# Processor.NewXPathCompiler方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            if ( args.Length < 2)
            {
                Console.Error.WriteLine("Syntax: demo <path-to-xml-file> <xpath-expression> [<num-iterations(default={0})>]", numIters);
                return;
            }

            var file = args[0];
            var xpath = args[1];

            if ( args.Length > 2)
            {
                numIters = int.Parse(args[2]);
            }

            Console.WriteLine("Loading {0}", file);

            var proc = new Processor();

            var ms_xp = System.Xml.XPath.XPathExpression.Compile(xpath);

            var xpc = proc.NewXPathCompiler();
            var xpe = xpc.Compile(xpath);
            var sel = xpe.Load();

            var doc = XDocument.Load(file);
            var ctx = proc.Wrap(doc);
            sel.ContextItem = ctx;

            var nt = new NameTable();
            XmlDocument xd = new XmlDocument(nt);
            xd.Load(file);

            var ctxXmlDoc = proc.NewDocumentBuilder().Wrap(xd);

            Console.WriteLine("Evaluating {0}", xpath);

            Time(() => Saxon(sel), "XDoc (Saxon)");
            Time(() => Native(ms_xp, doc), "XDoc (Native)");

            sel.ContextItem = ctxXmlDoc;

            Time(() => Saxon(sel), "XmlDoc (Saxon)");
            Time(() => Native(ms_xp, xd), "XmlDoc (Native)");
        }
开发者ID:zanyants,项目名称:saxon-xdoc,代码行数:46,代码来源:Program.cs

示例2: Load

        /// <summary>
        /// Load the XSLT file
        /// </summary>
        public void Load(string filename, bool profilingEnabled = false)
        {
            //register our eval() function
            processor = new Processor();
            processor.RegisterExtensionFunction(new SaxonEvaluate(processor.NewXPathCompiler()));

            //tracing
            if (profilingEnabled)
            {
                var profile = new TimingTraceListener();
                processor.Implementation.setTraceListener(profile);
                processor.Implementation.setLineNumbering(true);
                processor.Implementation.setCompileWithTracing(true);
                processor.Implementation.getDefaultXsltCompilerInfo().setCodeInjector(new TimingCodeInjector());
                profile.setOutputDestination(new java.io.PrintStream("profile.html"));
            }

            //capture the error information
            var compiler = processor.NewXsltCompiler();
            compiler.ErrorList = errorList;

            //compile the stylesheet
            var relativeFilename = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filename);
            try
            {
                var exec = compiler.Compile(XmlTextReader.Create(relativeFilename));

                //capture xsl:message output
                transform = exec.Load();
                transform.MessageListener = new SaxonMessageListener();
            }
            catch (Exception)
            {
                foreach (StaticError err in compiler.ErrorList)
                {
                    log.ErrorFormat("{0} ({1}, line {2})", err, err.ModuleUri, err.LineNumber);
                }
                throw;
            }
        }
开发者ID:jbowtie,项目名称:saxon-dotnet-extensions,代码行数:43,代码来源:SaxonTransform.cs

示例3: go

    /**
    * Run the application
    */

    public void go(String filename) {

        Processor processor = new Processor();
        XPathCompiler xpe = processor.NewXPathCompiler();

        // Build the source document. 

        DocumentBuilder builder = processor.NewDocumentBuilder();
        builder.BaseUri = new Uri(filename);
        builder.WhitespacePolicy = WhitespacePolicy.StripAll;
        XdmNode indoc = builder.Build(
                new FileStream(filename, FileMode.Open, FileAccess.Read));


        // Compile the XPath expressions used by the application

        QName wordName = new QName("", "", "word");
        xpe.DeclareVariable(wordName);

        XPathSelector findLine =
            xpe.Compile("//LINE[contains(., $word)]").Load();
        XPathSelector findLocation =
            xpe.Compile("concat(ancestor::ACT/TITLE, ' ', ancestor::SCENE/TITLE)").Load();
        XPathSelector findSpeaker =
            xpe.Compile("string(ancestor::SPEECH/SPEAKER[1])").Load();


        // Loop until the user enters "." to end the application

        while (true) {

            // Prompt for input
            Console.WriteLine("\n>>>> Enter a word to search for, or '.' to quit:\n");

            // Read the input
            String word = Console.ReadLine().Trim();
            if (word == ".") {
                break;
            }
            if (word != "") {

                // Set the value of the XPath variable
                currentWord = word;

                // Find the lines containing the requested word
                bool found = false;
                findLine.ContextItem = indoc;
                findLine.SetVariable(wordName, new XdmAtomicValue(word));
                foreach (XdmNode line in findLine) {

                    // Note that we have found at least one line
                    found = true;

                    // Find where it appears in the play
                    findLocation.ContextItem = line;
                    Console.WriteLine("\n" + findLocation.EvaluateSingle());

                    // Output the name of the speaker and the content of the line
                    findSpeaker.ContextItem = line;
                    Console.WriteLine(findSpeaker.EvaluateSingle() + ":  " + line.StringValue);

                }

                // If no lines were found, say so
                if (!found) {
                    Console.WriteLine("No lines were found containing the word '" + word + '\'');
                }
            }
        }

        // Finish when the user enters "."
        Console.WriteLine("Finished.");
    }
开发者ID:pombredanne,项目名称:https-dev.saxonica.com-repos-archive-opensource-,代码行数:77,代码来源:XPathExample.cs

示例4: run

        /// <summary>
        /// Execute an XPath expression that throws a dynamic error, and catch the error
        /// </summary>
        public override void run(Uri samplesDir)
        {
            // Create a Processor instance.
            Processor processor = new Processor();

            // Create the XPath expression.
            XPathCompiler compiler = processor.NewXPathCompiler();
            compiler.AllowUndeclaredVariables = true;
            XPathExecutable expression = compiler.Compile("1 + unknown()");
            XPathSelector selector = expression.Load();

            // Evaluate the XPath expression
            Console.WriteLine(selector.EvaluateSingle().ToString());
        }
开发者ID:nuxleus,项目名称:saxonica,代码行数:17,代码来源:ExamplesPE.cs

示例5: run

        public override void run(Uri samplesDir)
        {
            Processor processor = new Processor(true);


            String inputFileName = new Uri(samplesDir, "data/books.xml").ToString();

            processor.SchemaManager.Compile(new Uri(samplesDir, "data/books.xsd"));

            // add a reader
            XmlReader xmlReader = XmlReader.Create(UriConnection.getReadableUriStream(new Uri(samplesDir, "data/books.xml")));

            DocumentBuilder builder = processor.NewDocumentBuilder();

            builder.SchemaValidationMode = SchemaValidationMode.Strict;
            XdmNode doc = builder.Build(xmlReader);

            XPathCompiler compiler = processor.NewXPathCompiler();
            compiler.ImportSchemaNamespace("");
            XPathExecutable exp = compiler.Compile("if (//ITEM[@CAT='MMP']/QUANTITY instance of element(*,xs:integer)*) then 'true' else 'false'");
            XPathSelector eval = exp.Load();
            eval.ContextItem = doc;
            XdmAtomicValue result = (XdmAtomicValue)eval.EvaluateSingle();
            Console.WriteLine("Result type: " + result.ToString());
        }
开发者ID:zhuyue1314,项目名称:xcat,代码行数:25,代码来源:ExamplesEE.cs


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