Esempio n. 1
0
        /// <summary>
        /// Evaluate the expression, returning the result as an <c>XdmValue</c> (that is,
        /// a sequence of nodes and/or atomic values).
        /// </summary>
        /// <remarks>
        /// Although a singleton result <i>may</i> be represented as an <c>XdmItem</c>, there is
        /// no guarantee that this will always be the case. If you know that the expression will return at
        /// most one node or atomic value, it is best to use the <c>EvaluateSingle</c> method, which
        /// does guarantee that an <c>XdmItem</c> (or null) will be returned.
        /// </remarks>
        /// <returns>
        /// An <c>XdmValue</c> representing the results of the expression.
        /// </returns>

        public XdmValue Evaluate()
        {
            JValueRepresentation value = JSequenceExtent.makeSequenceExtent(
                exp.iterate(dynamicContext));

            return(XdmValue.Wrap(value));
        }
Esempio n. 2
0
        /// <summary>
        /// Wrap an XML DOM document, supplied as an <c>XmlNode</c>, as a Saxon XdmNode.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method must be applied at the level of the Document Node. Unlike the
        /// <c>Build</c> method, the original DOM is not copied. This saves memory and
        /// time, but it also means that it is not possible to perform operations such as
        /// whitespace stripping and schema validation.
        /// </para>
        /// </remarks>
        /// <param name="doc">The DOM document node to be wrapped</param>
        /// <returns>An <c>XdmNode</c>, the Saxon document node at the root of the tree of the resulting
        /// in-memory document
        /// </returns>

        public XdmNode Wrap(XmlDocument doc)
        {
            String           baseu   = (baseUri == null ? null : baseUri.ToString());
            JDocumentWrapper wrapper = new JDocumentWrapper(doc, baseu, config);

            return((XdmNode)XdmValue.Wrap(wrapper));
        }
Esempio n. 3
0
        /// <summary>
        /// Compile and execute an expression supplied as a <c>String</c>, with a given context item, where
        /// the expression is expected to return a single item as its result.
        /// </summary>
        /// <param name="expression">A string containing the source text of the XPath expression</param>
        /// <param name="contextItem">The context item to be used for evaluation of the XPath expression.
        /// May be null, in which case the expression is evaluated without any context item.</param>
        /// <returns>If the XPath expression returns a singleton, then the the <c>XdmItem</c>
        /// which is the result of evaluating the XPath expression. If the expression returns an empty sequence,
        /// then null. If the expression returns a sequence containing more than one item, then the first
        /// item in the result.</returns>
        /// <exception cref="StaticError">
        /// Throws a <c>Saxon.Api.StaticError</c> if there is any static error in the XPath expression.
        /// This includes both syntax errors, semantic errors such as references to undeclared functions or
        /// variables, and statically-detected type errors.
        /// </exception>
        /// <exception cref="DynamicError">
        /// Throws a <c>Saxon.Api.DynamicError</c> if there is any dynamic error during evaluation of the XPath expression.
        /// This includes, for example, referring to the context item if no context item was supplied.
        /// </exception>

        public XdmItem EvaluateSingle(String expression, XdmItem contextItem)
        {
            try
            {
                JXdmItem value = compiler.evaluateSingle(expression, contextItem == null ? null : XdmItem.FromXdmItemItemToJXdmItem(contextItem));
                return(value == null ? null : (XdmItem)XdmValue.Wrap(value.getUnderlyingValue()));
            }
            catch (JSaxonApiException err)
            {
                if (err.getCause() is JXPathException)
                {
                    JXPathException xpathException = (JXPathException)err.getCause();
                    if (xpathException.isStaticError())
                    {
                        throw new StaticError(err);
                    }
                    else
                    {
                        throw new DynamicError(err.getMessage());
                    }
                }
                else
                {
                    throw new StaticError(err);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Get the sequence of items in the form of an <c>IList</c>
        /// </summary>
        /// <returns>
        /// The list of items making up this value. Each item in the list
        /// will be an object of type <c>XdmItem</c>
        /// </returns>

        public IList GetList()
        {
            if (value == null)
            {
                return(new ArrayList());
            }
            else if (value is Item)
            {
                ArrayList list = new ArrayList(1);
                list.Add((NodeInfo)value);
                return(list);
            }
            else
            {
                ArrayList        list = new ArrayList();
                SequenceIterator iter = ((Value)value).iterate(null);
                while (true)
                {
                    Item jitem = iter.next();
                    if (jitem == null)
                    {
                        break;
                    }
                    list.Add((XdmItem)XdmValue.Wrap(jitem));
                }
                return(list);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Evaluate the query, returning the result as an <c>XdmItem</c> (that is,
        /// a single node or atomic value).
        /// </summary>
        /// <returns>
        /// An <c>XdmItem</c> representing the result of the query, or null if the query
        /// returns an empty sequence. If the query returns a sequence of more than one item,
        /// any items after the first are ignored.
        /// </returns>
        /// <exception cref="DynamicError">Throws a DynamicError if any run-time failure
        /// occurs while evaluating the expression.</exception>

        public XdmItem EvaluateSingle()
        {
            try {
                return((XdmItem)XdmValue.Wrap(exp.iterator(context).next()));
            } catch (JXPathException err) {
                throw new DynamicError(err);
            }
        }
Esempio n. 6
0
        // Build a document from a given stream, with the base URI supplied
        // as an extra argument

        internal XdmNode Build(TextReader input, Uri baseUri)
        {
            Source source;

            if (processor.GetProperty("http://saxon.sf.net/feature/preferJaxpParser") == "true")
            {
                source = new StreamSource(new DotNetReader(input), baseUri.ToString());
                source = AugmentedSource.makeAugmentedSource(source);
                ((AugmentedSource)source).setEntityResolver(new DotNetURIResolver(XmlResolver));
            }
            else
            {
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.ProhibitDtd = false;   // must expand entity references


                //((XmlTextReader)parser).Normalization = true;
                switch (whitespacePolicy)
                {
                case WhitespacePolicy.PreserveAll:
                    settings.IgnoreWhitespace = false;
                    //((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.All;
                    break;

                case WhitespacePolicy.StripAll:
                    settings.IgnoreWhitespace = true;
                    //((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.None;
                    break;

                case WhitespacePolicy.StripIgnorable:
                    settings.IgnoreWhitespace = true;
                    //((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.Significant;
                    break;
                }
                if (xmlResolver != null)
                {
                    settings.XmlResolver = xmlResolver;
                }

                settings.ValidationType = (dtdValidation ? ValidationType.DTD : ValidationType.None);

                XmlReader parser = XmlReader.Create(input, settings, baseUri.ToString());
                source = new PullSource(new DotNetPullProvider(parser));
                source.setSystemId(baseUri.ToString());
            }
            source = augmentSource(source);
            DocumentInfo doc = null;

            try
            {
                doc = config.buildDocument(source);
            }
            catch (net.sf.saxon.trans.XPathException e)
            {
                throw new StaticError(e);
            }
            return((XdmNode)XdmValue.Wrap(doc));
        }
Esempio n. 7
0
        /// <summary>
        /// Evaluate the XPath expression, returning the result as an <c>XdmItem</c> (that is,
        /// a single node or atomic value).
        /// </summary>
        /// <returns>
        /// An <c>XdmItem</c> representing the result of the expression, or null if the expression
        /// returns an empty sequence. If the expression returns a sequence of more than one item,
        /// any items after the first are ignored.
        /// </returns>


        public XdmItem EvaluateSingle()
        {
            net.sf.saxon.om.Item i = exp.evaluateSingle(dynamicContext);
            if (i == null)
            {
                return(null);
            }
            return((XdmItem)XdmValue.Wrap(i));
        }
Esempio n. 8
0
        /// <summary>
        /// Evaluate the expression, returning the result as an <c>XdmValue</c> (that is,
        /// a sequence of nodes and/or atomic values).
        /// </summary>
        /// <remarks>
        /// Although a singleton result <i>may</i> be represented as an <c>XdmItem</c>, there is
        /// no guarantee that this will always be the case. If you know that the expression will return at
        /// most one node or atomic value, it is best to use the <c>EvaluateSingle</c> method, which
        /// does guarantee that an <c>XdmItem</c> (or null) will be returned.
        /// </remarks>
        /// <returns>
        /// An <c>XdmValue</c> representing the results of the expression.
        /// </returns>

        public XdmValue Evaluate()
        {
            JXPathContextMajor context = new JXPathContextMajor(contextItem, config);

            context.setStackFrame(env.getStackFrameMap(), variableValues);
            JValueRepresentation value = JSequenceExtent.makeSequenceExtent(exp.iterate(context));

            return(XdmValue.Wrap(value));
        }
Esempio n. 9
0
        /// <summary>
        /// Evaluate the expression, returning the result as an <c>XdmValue</c> (that is,
        /// a sequence of nodes, atomic values, and possibly function items such as maps and arrays).
        /// </summary>
        /// <remarks>
        /// Although a singleton result <i>may</i> be represented as an <c>XdmItem</c>, there is
        /// no guarantee that this will always be the case. If you know that the expression will return at
        /// most one node or atomic value, it is best to use the <c>EvaluateSingle</c> method, which
        /// does guarantee that an <c>XdmItem</c> (or null) will be returned.
        /// </remarks>
        /// <returns>
        /// An <c>XdmValue</c> representing the results of the expression.
        /// </returns>
        /// <exception cref="DynamicError">
        /// Throws <c>Saxon.Api.DynamicError</c> if the evaluation of the XPath expression fails
        /// with a dynamic error.
        /// </exception>

        public XdmValue Evaluate()
        {
            try {
                net.sf.saxon.s9api.XdmValue value = selector.evaluate();
                return(value == null ? null : XdmValue.Wrap(value.getUnderlyingValue()));
            } catch (JSaxonApiException err) {
                throw new DynamicError(err);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Evaluate the query, returning the result as an <c>XdmValue</c> (that is,
        /// a sequence of nodes and/or atomic values).
        /// </summary>
        /// <returns>
        /// An <c>XdmValue</c> representing the results of the query
        /// </returns>
        /// <exception cref="DynamicError">Throws a DynamicError if any run-time failure
        /// occurs while evaluating the query.</exception>

        public XdmValue Evaluate()
        {
            try {
                ValueRepresentation value = SequenceExtent.makeSequenceExtent(exp.iterator(context));
                return(XdmValue.Wrap(value));
            } catch (JXPathException err) {
                throw new DynamicError(err);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Evaluate the expression, returning the result as an <c>XdmValue</c> (that is,
        /// a sequence of nodes and/or atomic values).
        /// </summary>
        /// <remarks>
        /// Although a singleton result <i>may</i> be represented as an <c>XdmItem</c>, there is
        /// no guarantee that this will always be the case. If you know that the expression will return at
        /// most one node or atomic value, it is best to use the <c>EvaluateSingle</c> method, which
        /// does guarantee that an <c>XdmItem</c> (or null) will be returned.
        /// </remarks>
        /// <returns>
        /// An <c>XdmValue</c> representing the results of the expression.
        /// </returns>
        /// <exception cref="DynamicError">
        /// Throws <c>Saxon.Api.DynamicError</c> if the evaluation of the XPath expression fails
        /// with a dynamic error.
        /// </exception>

        public XdmValue Evaluate()
        {
            try {
                JSequence value = (JSequence)JSequenceExtent.makeSequenceExtent(
                    exp.iterate(dynamicContext));
                return(XdmValue.Wrap(value));
            } catch (net.sf.saxon.trans.XPathException err) {
                throw new DynamicError(err);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Evaluate the query, returning the result as an <c>XdmItem</c> (that is,
        /// a single node or atomic value).
        /// </summary>
        /// <returns>
        /// An <c>XdmItem</c> representing the result of the query, or null if the query
        /// returns an empty sequence. If the query returns a sequence of more than one item,
        /// any items after the first are ignored.
        /// </returns>
        /// <exception cref="DynamicError">Throws a <c>DynamicError</c> if any run-time failure
        /// occurs while evaluating the expression.</exception>

        public XdmItem EvaluateSingle()
        {
            try
            {
                return((XdmItem)XdmValue.Wrap(evaluator.evaluateSingle().getUnderlyingValue()));
            }
            catch (JSaxonApiException err)
            {
                throw new DynamicError(err);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Evaluate the XPath expression, returning the result as an <c>XdmItem</c> (that is,
        /// a single node or atomic value).
        /// </summary>
        /// <returns>
        /// An <c>XdmItem</c> representing the result of the expression, or null if the expression
        /// returns an empty sequence. If the expression returns a sequence of more than one item,
        /// any items after the first are ignored.
        /// </returns>
        /// <exception cref="DynamicError">
        /// Throws <c>Saxon.Api.DynamicError</c> if the evaluation of the XPath expression fails
        /// with a dynamic error.
        /// </exception>


        public XdmItem EvaluateSingle()
        {
            try
            {
                JXdmItem item = selector.evaluateSingle();
                return(item == null ? null : (XdmItem)XdmValue.Wrap(item.getUnderlyingValue().materialize()));
            }
            catch (JSaxonApiException err)
            {
                throw new DynamicError(err);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Evaluate the XPath expression, returning the result as an <c>XdmItem</c> (that is,
        /// a single node or atomic value).
        /// </summary>
        /// <returns>
        /// An <c>XdmItem</c> representing the result of the expression, or null if the expression
        /// returns an empty sequence. If the expression returns a sequence of more than one item,
        /// any items after the first are ignored.
        /// </returns>


        public XdmItem EvaluateSingle()
        {
            JXPathContextMajor context = new JXPathContextMajor(contextItem, config);

            context.setStackFrame(env.getStackFrameMap(), variableValues);
            net.sf.saxon.om.Item i = exp.iterate(context).next();
            if (i == null)
            {
                return(null);
            }
            return((XdmItem)XdmValue.Wrap(i));
        }
Esempio n. 15
0
        /// <summary>
        /// Evaluate the query, returning the result as an <c>XdmValue</c> (that is,
        /// a sequence of nodes and/or atomic values).
        /// </summary>
        /// <returns>
        /// An <c>XdmValue</c> representing the results of the query
        /// </returns>
        /// <exception cref="DynamicError">Throws a <c>DynamicError</c> if any run-time failure
        /// occurs while evaluating the query.</exception>

        public XdmValue Evaluate()
        {
            try
            {
                JXdmValue value = evaluator.evaluate();
                return(XdmValue.Wrap(value.getUnderlyingValue()));
            }
            catch (JSaxonApiException err)
            {
                throw new DynamicError(err);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Evaluate the XPath expression, returning the result as an <c>XdmItem</c> (that is,
        /// a single node or atomic value).
        /// </summary>
        /// <returns>
        /// An <c>XdmItem</c> representing the result of the expression, or null if the expression
        /// returns an empty sequence. If the expression returns a sequence of more than one item,
        /// any items after the first are ignored.
        /// </returns>
        /// <exception cref="DynamicError">
        /// Throws <c>Saxon.Api.DynamicError</c> if the evaluation of the XPath expression fails
        /// with a dynamic error.
        /// </exception>


        public XdmItem EvaluateSingle()
        {
            try
            {
                net.sf.saxon.om.Item i = exp.evaluateSingle(dynamicContext);
                if (i == null)
                {
                    return(null);
                }
                return((XdmItem)XdmValue.Wrap(i));
            } catch (net.sf.saxon.trans.XPathException err) {
                throw new DynamicError(err);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Call a global user-defined function in the compiled query.
        /// </summary>
        /// <remarks>
        /// If this is called more than once (to evaluate the same function repeatedly with different arguments,
        /// or to evaluate different functions) then the sequence of evaluations uses the same values of global
        /// variables including external variables (query parameters); the effect of any changes made to query parameters
        /// between calls is undefined.
        /// </remarks>
        /// <param name="function">
        /// The name of the function to be called
        /// </param>
        /// <param name="arguments">
        /// The values of the arguments to be supplied to the function. These
        /// must be of the correct type as defined in the function signature (there is no automatic
        /// conversion to the required type).
        /// </param>
        /// <exception cref="ArgumentException">If no function has been defined with the given name and arity
        /// or if any of the arguments does not match its required type according to the function
        /// signature.</exception>
        /// <exception cref="DynamicError">If a dynamic error occurs in evaluating the function.
        /// </exception>

        public XdmValue CallFunction(QName function, XdmValue[] arguments)
        {
            try {
                JXdmValue[] vr = new JXdmValue[arguments.Length];
                for (int i = 0; i < arguments.Length; i++)
                {
                    vr[i] = XdmValue.FromGroundedValueToJXdmValue(arguments[i].value);
                }
                JSequence result = evaluator.callFunction(function.UnderlyingQName(), vr).getUnderlyingValue();
                return(XdmValue.Wrap(result));
            } catch (JSaxonApiException e) {
                throw new DynamicError(e);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Load an XML document, delivered using an XmlReader.
        /// </summary>
        /// <remarks>
        /// <para>The XmlReader is responsible for parsing the document; this method builds a tree
        /// representation of the document (in an internal Saxon format) and returns its document node.
        /// The XmlReader is not required to perform validation but it must expand any entity references.
        /// Saxon uses the properties of the <c>XmlReader</c> as supplied.</para>
        /// <para>Use of a plain <c>XmlTextReader</c> is discouraged, because it does not expand entity
        /// references. This should only be used if you know in advance that the document will contain
        /// no entity references (or perhaps if your query or stylesheet is not interested in the content
        /// of text and attribute nodes). Instead, with .NET 1.1 use an <c>XmlValidatingReader</c> (with <c>ValidationType</c>
        /// set to <c>None</c>). The constructor for <c>XmlValidatingReader</c> is obsolete in .NET 2.0,
        /// but the same effect can be achieved by using the <c>Create</c> method of <c>XmlReader</c> with
        /// appropriate <c>XmlReaderSettings</c></para>
        /// <para>Conformance with the W3C specifications requires that the <c>Normalization</c> property
        /// of an <c>XmlTextReader</c> should be set to <c>true</c>. However, Saxon does not insist
        /// on this.</para>
        /// <para>If the <c>XmlReader</c> performs schema validation, Saxon will ignore any resulting type
        /// information. Type information can only be obtained by using Saxon's own schema validator, which
        /// will be run if the <c>SchemaValidationMode</c> property is set to <c>Strict</c> or <c>Lax</c></para>
        /// <para>Note that the Microsoft <c>System.Xml</c> parser does not report whether attributes are
        /// defined in the DTD as being of type <c>ID</c> and <c>IDREF</c>. This is true whether or not
        /// DTD-based validation is enabled. This means that such attributes are not accessible to the
        /// <c>id()</c> and <c>idref()</c> functions.</para>
        /// <para>Note that setting the <c>XmlResolver</c> property of the <c>DocumentBuilder</c>
        /// has no effect when this method is used; if an <c>XmlResolver</c> is required, it must
        /// be set on the <c>XmlReader</c> itself.</para>
        /// </remarks>
        /// <param name="reader">The XMLReader that supplies the parsed XML source</param>
        /// <returns>An <c>XdmNode</c>, the document node at the root of the tree of the resulting
        /// in-memory document
        /// </returns>

        public XdmNode Build(XmlReader reader)
        {
            PullProvider pp = new DotNetPullProvider(reader);

            pp.setPipelineConfiguration(config.makePipelineConfiguration());
            // pp = new PullTracer(pp);  /* diagnostics */
            Source source = new PullSource(pp);

            source.setSystemId(reader.BaseURI);
            source = augmentSource(source);
            DocumentInfo doc = config.buildDocument(source);

            return((XdmNode)XdmValue.Wrap(doc));
        }
Esempio n. 19
0
        // Build a document from a given stream, with the base URI supplied
        // as an extra argument

        internal XdmNode Build(Stream input, Uri baseUri)
        {
            Source source;

            if (processor.GetProperty("http://saxon.sf.net/feature/preferJaxpParser") == "true")
            {
                source = new StreamSource(new DotNetInputStream(input), baseUri.ToString());
            }
            else
            {
                XmlReader parser = new XmlTextReader(baseUri.ToString(), input);
                ((XmlTextReader)parser).Normalization = true;
                switch (whitespacePolicy)
                {
                case WhitespacePolicy.PreserveAll:
                    ((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.All;
                    break;

                case WhitespacePolicy.StripAll:
                    ((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.None;
                    break;

                case WhitespacePolicy.StripIgnorable:
                    ((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.Significant;
                    break;
                }
                if (xmlResolver != null)
                {
                    ((XmlTextReader)parser).XmlResolver = xmlResolver;
                }
                // Always need a validating parser, because that's the only way to get entity references expanded
                parser = new XmlValidatingReader(parser);
                if (dtdValidation)
                {
                    ((XmlValidatingReader)parser).ValidationType = ValidationType.DTD;
                }
                else
                {
                    ((XmlValidatingReader)parser).ValidationType = ValidationType.None;
                }
                source = new PullSource(new DotNetPullProvider(parser));
                source.setSystemId(baseUri.ToString());
            }
            source = augmentSource(source);
            DocumentInfo doc = config.buildDocument(source);

            return((XdmNode)XdmValue.Wrap(doc));
        }
Esempio n. 20
0
        /// <summary>
        /// Load an XML document supplied as raw (lexical) XML on a Stream.
        /// </summary>
        /// <remarks>
        /// <para>The document is parsed using the <c>System.Xml</c> parser.</para>
        /// <para>Before calling this method, the BaseUri property must be set to identify the
        /// base URI of this document, used for resolving any relative URIs contained within it.</para>
        /// <para>Note that the Microsoft <c>System.Xml</c> parser does not report whether attributes are
        /// defined in the DTD as being of type <c>ID</c> and <c>IDREF</c>. This is true whether or not
        /// DTD-based validation is enabled. This means that such attributes are not accessible to the
        /// <c>id()</c> and <c>idref()</c> functions.</para>
        /// </remarks>
        /// <param name="input">The Stream containing the XML source to be parsed</param>
        /// <returns>An <c>XdmNode</c>, the document node at the root of the tree of the resulting
        /// in-memory document
        /// </returns>

        public XdmNode Build(Stream input)
        {
            if (baseUri == null)
            {
                throw new ArgumentException("No base URI suppplied");
            }
            Source source = new StreamSource(new DotNetInputStream(input));

            source.setSystemId(baseUri.ToString());
            source = augmentSource(source);
            StaticQueryContext env = new StaticQueryContext(config);
            //env.setURIResolver(new DotNetURIResolver(xmlResolver));
            DocumentInfo doc = env.buildDocument(source);

            return((XdmNode)XdmValue.Wrap(doc));
        }
Esempio n. 21
0
        public net.sf.saxon.s9api.XdmValue call(net.sf.saxon.s9api.XdmValue[] xvarr)
        {
            XdmValue[] values = new XdmValue[xvarr.Length];
            int        len    = xvarr.Length;

            for (int i = 0; i < len; i++)
            {
                values[i] = XdmValue.Wrap(xvarr[i].getUnderlyingValue());
            }
            try {
                XdmValue result = definition.Call(values);
                return(XdmValue.FromGroundedValueToJXdmValue(result.value));
            }
            catch (Exception ex) {
                throw new DynamicError(ex.Message);
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Execute an updating query.
        /// </summary>
        /// <returns>An array containing the root nodes of documents that have been
        /// updated by the query.</returns>
        /// <exception cref="DynamicError">Throws a <c>DynamicError</c> if any run-time failure
        /// occurs while evaluating the expression, or if the expression is not an
        /// updating query.</exception>

        public XdmNode[] RunUpdate()
        {
            try
            {
                evaluator.run();
                java.util.Iterator updatedDocsIter = evaluator.getUpdatedDocuments();
                List <XdmNode>     resultList      = new List <XdmNode>();

                for (; updatedDocsIter.hasNext();)

                {
                    resultList.Add((XdmNode)XdmValue.Wrap(((net.sf.saxon.s9api.XdmNode)updatedDocsIter.next()).getUnderlyingNode()));
                }
                XdmNode[] result = resultList.ToArray();
                return(result);
            }
            catch (JSaxonApiException err)
            {
                throw new DynamicError(err);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Load an XML document, delivered using an XmlReader.
        /// </summary>
        /// <remarks>
        /// <para>The XmlReader is responsible for parsing the document; this method builds a tree
        /// representation of the document (in an internal Saxon format) and returns its document node.
        /// The XmlReader is not required to perform validation but it must expand any entity references.
        /// Saxon uses the properties of the <c>XmlReader</c> as supplied.</para>
        /// <para>Use of a plain <c>XmlTextReader</c> is discouraged, because it does not expand entity
        /// references. This should only be used if you know in advance that the document will contain
        /// no entity references (or perhaps if your query or stylesheet is not interested in the content
        /// of text and attribute nodes). Instead, with .NET 1.1 use an <c>XmlValidatingReader</c> (with <c>ValidationType</c>
        /// set to <c>None</c>). The constructor for <c>XmlValidatingReader</c> is obsolete in .NET 2.0,
        /// but the same effect can be achieved by using the <c>Create</c> method of <c>XmlReader</c> with
        /// appropriate <c>XmlReaderSettings</c></para>
        /// <para>Conformance with the W3C specifications requires that the <c>Normalization</c> property
        /// of an <c>XmlTextReader</c> should be set to <c>true</c>. However, Saxon does not insist
        /// on this.</para>
        /// <para>If the <c>XmlReader</c> performs schema validation, Saxon will ignore any resulting type
        /// information. Type information can only be obtained by using Saxon's own schema validator, which
        /// will be run if the <c>SchemaValidationMode</c> property is set to <c>Strict</c> or <c>Lax</c></para>
        /// <para>Note that the Microsoft <c>System.Xml</c> parser does not report whether attributes are
        /// defined in the DTD as being of type <c>ID</c> and <c>IDREF</c>. This is true whether or not
        /// DTD-based validation is enabled. This means that such attributes are not accessible to the
        /// <c>id()</c> and <c>idref()</c> functions.</para>
        /// <para>Note that setting the <c>XmlResolver</c> property of the <c>DocumentBuilder</c>
        /// has no effect when this method is used; if an <c>XmlResolver</c> is required, it must
        /// be set on the <c>XmlReader</c> itself.</para>
        /// </remarks>
        /// <param name="reader">The XMLReader that supplies the parsed XML source</param>
        /// <returns>An <c>XdmNode</c>, the document node at the root of the tree of the resulting
        /// in-memory document
        /// </returns>

        public XdmNode Build(XmlReader reader)
        {
            PullProvider pp = new DotNetPullProvider(reader);

            pp.setPipelineConfiguration(config.makePipelineConfiguration());
            // pp = new PullTracer(pp);  /* diagnostics */
            Source source = new PullSource(pp);

            source.setSystemId(reader.BaseURI);
            source = augmentSource(source);
            DocumentInfo doc = null;

            try
            {
                doc = config.buildDocument(source);
            }
            catch (net.sf.saxon.trans.XPathException e)
            {
                throw new StaticError(e);
            }
            return((XdmNode)XdmValue.Wrap(doc));
        }
Esempio n. 24
0
        /// <summary>
        /// Execute an updating query.
        /// </summary>
        /// <returns>An array containing the root nodes of documents that have been
        /// updated by the query.</returns>
        /// <exception cref="DynamicError">Throws a DynamicError if any run-time failure
        /// occurs while evaluating the expression, or if the expression is not an
        /// updating query.</exception>

        public XdmNode[] RunUpdate()
        {
            if (!exp.isUpdateQuery())
            {
                throw new DynamicError("Not an updating query");
            }
            try
            {
                java.util.Set updatedDocs = exp.runUpdate(context);
                XdmNode[]     result      = new XdmNode[updatedDocs.size()];
                int           i           = 0;
                for (java.util.Iterator iter = updatedDocs.iterator(); iter.hasNext();)
                {
                    result[i++] = (XdmNode)XdmValue.Wrap((NodeInfo)iter.next());
                }
                return(result);
            }
            catch (JXPathException err)
            {
                throw new DynamicError(err);
            }
        }
Esempio n. 25
0
        ///<summary>
        /// Call a global user-defined function in the compiled query.
        ///</summary>
        ///<remarks>
        /// If this is called more than once (to evaluate the same function repeatedly with different arguments,
        /// or to evaluate different functions) then the sequence of evaluations uses the same values of global
        /// variables including external variables (query parameters); the effect of any changes made to query parameters
        /// between calls is undefined.
        /// </remarks>
        /// <param name="function">
        /// The name of the function to be called
        /// </param>
        /// <param name="arguments">
        /// The values of the arguments to be supplied to the function. These
        /// must be of the correct type as defined in the function signature (there is no automatic
        /// conversion to the required type).
        /// </param>
        /// <exception cref="ArgumentException">If no function has been defined with the given name and arity
        /// or if any of the arguments does not match its required type according to the function
        /// signature.</exception>
        /// <exception cref="DynamicError">If a dynamic error occurs in evaluating the function.
        /// </exception>

        public XdmValue CallFunction(QName function, XdmValue[] arguments)
        {
            JUserFunction fn = exp.getStaticContext().getUserDefinedFunction(
                function.Uri, function.LocalName, arguments.Length);

            if (fn == null)
            {
                throw new ArgumentException("No function with name " + function.ClarkName +
                                            " and arity " + arguments.Length + " has been declared in the query");
            }
            try {
                // TODO: use the same controller in other interfaces such as run(), and expose it in a trapdoor API
                if (controller == null)
                {
                    controller = exp.newController();
                    context.initializeController(controller);
                    controller.defineGlobalParameters();
                }
                ValueRepresentation[] vr = new ValueRepresentation[arguments.Length];

                for (int i = 0; i < arguments.Length; i++)
                {
                    SequenceType type = fn.getParameterDefinitions()[i].getRequiredType();
                    vr[i] = arguments[i].Unwrap();
                    if (!type.matches(Value.asValue(vr[i]), controller.getConfiguration()))
                    {
                        throw new ArgumentException("Argument " + (i + 1) +
                                                    " of function " + function.ClarkName +
                                                    " does not match the required type " + type.toString());
                    }
                }
                ValueRepresentation result = fn.call(vr, controller);
                return(XdmValue.Wrap(result));
            } catch (JXPathException e) {
                throw new DynamicError(e);
            }
        }
Esempio n. 26
0
 public override object wrapAsXdmValue(JValue value)
 {
     return(XdmValue.Wrap(value));
 }
Esempio n. 27
0
 /// <summary>
 /// Get the value that has set for a schema processor (a parameter defined in the schema using the <c>saxon:param</c>
 /// extension)
 /// </summary>
 /// <param name="name">the parameter whose name is required</param>
 /// <returns>the value that has been set for the parameter, or the EmptySequence if no value has been set</returns>
 public XdmValue GetParameter(QName name)
 {
     net.sf.saxon.s9api.XdmValue value = schemaValidator.getParameter(name.UnderlyingQName());
     return(value == null ? null : XdmValue.Wrap(value.getUnderlyingValue()));
 }
Esempio n. 28
0
        /// <summary>Locate and compile a stylesheet identified by an &lt;?xml-stylesheet?&gt;
        /// processing instruction within a source document.
        /// </summary>
        /// <param name="source">The document node of the source document containing the
        /// xml-stylesheet processing instruction.</param>
        /// <returns>An <c>XsltExecutable</c> which represents the compiled stylesheet object.</returns>
        /// <remarks>There are some limitations in the current implementation. The media type
        /// is ignored, as are the other parameters of the xml-stylesheet instruction. The
        /// href attribute must either reference an embedded stylesheet within the same
        /// document or a non-embedded external stylesheet.</remarks>

        public XsltExecutable CompileAssociatedStylesheet(XdmNode source)
        {
            // TODO: lift the restrictions
            if (source == null || source.NodeKind != XmlNodeType.Document)
            {
                throw new ArgumentException("Source must be a document node");
            }
            IEnumerator kids     = source.EnumerateAxis(XdmAxis.Child);
            QName       xmlstyle = new QName("", "xml-stylesheet");

            while (kids.MoveNext())
            {
                XdmNode n = (XdmNode)kids.Current;
                if (n.NodeKind == XmlNodeType.ProcessingInstruction &&
                    n.NodeName.Equals(xmlstyle))
                {
                    // TODO: check the media type
                    String href = JProcInstParser.getPseudoAttribute(n.StringValue, "href");
                    if (href == null)
                    {
                        throw new DynamicError("xml-stylesheet processing instruction has no href attribute");
                    }
                    String fragment = null;
                    int    hash     = href.LastIndexOf('#');
                    if (hash == 0)
                    {
                        if (href.Length == 1)
                        {
                            throw new DynamicError("Relative URI of '#' is invalid");
                        }
                        fragment = href.Substring(1);
                        JNodeInfo target        = ((JDocumentInfo)source.value).selectID(fragment);
                        XdmNode   targetWrapper = null;
                        if (target == null)
                        {
                            // There's a problem here because the Microsoft XML parser doesn't
                            // report id values, so selectID() will never work. We work around that
                            // by looking for an attribute named "id" appearing on an xsl:stylesheet
                            // or xsl:transform element
                            QName       qid = new QName("", "id");
                            IEnumerator en  = source.EnumerateAxis(XdmAxis.Descendant);
                            while (en.MoveNext())
                            {
                                XdmNode x = (XdmNode)en.Current;
                                if (x.NodeKind == XmlNodeType.Element &&
                                    x.NodeName.Uri == "http://www.w3.org/1999/XSL/Transform" &&
                                    (x.NodeName.LocalName == "stylesheet" || x.NodeName.LocalName == "transform" &&
                                     x.GetAttributeValue(qid) == fragment))
                                {
                                    targetWrapper = x;
                                }
                            }
                        }
                        else
                        {
                            targetWrapper = (XdmNode)XdmValue.Wrap(target);
                        }
                        if (targetWrapper == null)
                        {
                            throw new DynamicError("No element with id='" + fragment + "' found");
                        }
                        return(Compile(targetWrapper));
                    }
                    else if (hash > 0)
                    {
                        throw new NotImplementedException("href cannot identify an embedded stylesheet in a different document");
                    }
                    else
                    {
                        Uri uri = new Uri(n.BaseUri, href);
                        return(Compile(uri));
                    }
                }
            }
            throw new DynamicError("xml-stylesheet processing instruction not found");
        }
Esempio n. 29
0
        /// <summary>
        /// Create an atomic value that wraps an external object. Such values can be used
        /// in conjunction with extension functions.
        /// </summary>
        /// <param name="external">The object to be wrapped.</param>
        /// <returns>The wrapped object</returns>

        public static XdmAtomicValue wrapExternalObject(object external)
        {
            return((XdmAtomicValue)XdmValue.Wrap(new DotNetObjectValue(external)));
        }