Saxon.Api
Class Processor
-
public class Processor
- implements net.sf.saxon.Configuration.ApiProvider
The Processor
class serves three purposes: it allows global Saxon configuration
options to be set; it acts as a factory for generating XQuery, XPath, and XSLT
compilers; and it owns certain shared resources such as the Saxon NamePool
and
compiled schemas. This is the first object that a Saxon application should create.
Once
established, a Processor
may be used in multiple threads.
Constructor Summary |
|
---|---|
Processor ()
Create a new |
|
Processor (bool licensedEdition)
Create a |
|
Processor (bool licensedEdition, bool loadLocally)
Create a |
|
Processor (Stream configurationFile) Deprecated Use the Processor(Stream, Uri) constructor instead. |
|
Processor (Stream configurationFile, Uri baseUri)
Create a |
Property Summary |
|
---|---|
ICollectionFinder | CollectionFinder A used-supplied callback that is used to retrieve a resource collection given a collection URI. |
string | Edition Get the Saxon product edition (for example, "EE" for Enterprise Edition) |
TextWriter | ErrorWriter
A |
net.sf.saxon.Configuration | Implementation
The underlying |
net.sf.saxon.s9api.Processor | JProcessor
The underlying |
string | ProductTitle
Get the full name of the Saxon product version implemented by this |
string | ProductVersion Get the Saxon product version number (for example, "9.2.0.2") |
IQueryResolver | QueryResolver
A user-supplied |
SchemaManager | SchemaManager
Gets the |
StandardCollectionFinder | StandardCollectionFinder
The standard (built-in) collection finder that is used by default if no user-defined
collection finder has been supplied. This is exposed as a property of the |
XmlResolver | XmlResolver
An |
decimal | XmlVersion
The XML version used in this |
Method Summary |
|
---|---|
void | BindExtensions(string uri, Type type) Declare a mapping from a specific namespace URI to a .NET class This will get applied to Saxon-PEN or Saxon-EEN product |
void | DeclareCollation(Uri uri, CompareInfo compareInfo, CompareOptions options)
Create a collation based on a given |
string | GetMediaTypeForFileExtension(string extension) Get the media type to be associated with a file extension by the standard collection handler |
string | GetProperty(string name) Get the value of a configuration property |
<T> T | GetProperty(Feature<T> feature) Get a property of the configuration |
DocumentBuilder | NewDocumentBuilder()
Create a new |
Serializer | NewSerializer()
Create a |
Serializer | NewSerializer(TextWriter textWriter)
Create a |
Serializer | NewSerializer(Stream stream)
Create a |
XPathCompiler | NewXPathCompiler()
Create a new |
XQueryCompiler | NewXQueryCompiler()
Create a new |
XsltCompiler | NewXsltCompiler()
Create a new |
void | RegisterCollection(string collectionURI, IResourceCollection collection)
Register a specific URI and bind it to a specific |
void | RegisterCollection(Uri collectionUri, IEnumerable contents)
Register a named collection. A collection is identified by a URI (the collection URI),
and its content is represented by an |
void | RegisterExtensionFunction(ExtensionFunctionDefinition function)
Register an extension function with the |
void | RegisterExtensionFunction(ExtensionFunction function)
Register a simple external/extension function that is to be made available within
any stylesheet, query
or XPath expression compiled under the control of this |
void | RegisterFileExtension(string extension, string mediaType) Set the media type to be associated with a file extension by the standard collection handler |
void | RegisterMediaType(string contentType, IResourceFactory factory) Associated a media type with a resource factory. This methodm may be called to customize the behaviour of a collection to recognize different file extensions |
void | SetProperty(string name, string value) Set a configuration property |
<T> void | SetProperty(Feature<T> feature, T value) Set a configuration property |
void | WriteXdmValue(XdmValue sequence, XmlDestination destination)
Copy an |
Constructor Detail
Processor
Create a new Processor
. This Processor
will have capabilities that depend on the version
of the software that has been loaded, and on the features that have been licensed.
Processor
Create a Processor
.
Parameters:
licensedEdition
- Set to true if the Processor
is to use a licensed edition of Saxon
(that is, Saxon-PE or Saxon-EE). If true, the Processor
will attempt to enable the capabilities
of the licensed edition of Saxon, according to the version of the software that is
loaded, and will
verify the license key. If false, the Processor
will load a default Configuration
that gives restricted
capability and does not require a license, regardless of which version of the software
is actually being run.Processor
Create a Processor
.
Parameters:
licensedEdition
- Set to true if the Processor
is to use a licensed edition of Saxon
(that is, Saxon-PE or Saxon-EE). If true, the Processor
will attempt to enable the capabilities
of the licensed edition of Saxon, according to the version of the software that is
loaded, and will
verify the license key. If false, the Processor
will load a default Configuration
that gives restricted
capability and does not require a license, regardless of which version of the software
is actually being run.loadLocally
- This option has no effect at this release.Processor
Deprecated Use the Processor(Stream, Uri) constructor instead.
Create a Processor
, based on configuration information supplied in a configuration file.
Parameters:
configurationFile
- A stream holding the text of the XML configuration file. Details of the file format
can be found in the Saxon documentation.Processor
Create a Processor
, based on configuration information supplied in a configuration file.
Parameters:
configurationFile
- A stream holding the text of the XML configuration file. Details of the file format
can be found in the Saxon documentation.baseUri
- baseUri of the configuration file used for resolving any relative URIs in the fileProperty Detail
CollectionFinder
A used-supplied callback that is used to retrieve a resource collection given a collection URI.
If no collection finder is supplied, then the built-in collection finder is used.
The
built-in collection finder recognizes various kinds of collection including directory
collections
and catalog collections. A user-defined collection finder can delegate to the built-in
collection finder
by invoking the function available as Processor.StandardCollectionFinder
.
A collection finder should be set only while the processor is being initialized; the effect of changing the collection finder (or changing any data on which it depends) while queries or transformations are in progress is undefined.
The collection finder returns a set of IResource
objects. Typically a used-defined
class implementing IResource
is used. An IResource
has a resource URI, a content type
(MIME or media type), and a method to deliver the resource content as an XdmItem
. Typically
fetching the resource over the network, and parsing it according to the rules of the
relevant content
type, is delayed until the GetXdmItem
method is called.
For deterministic results, and for W3C conformance, it is recommended that the supplied function should be deterministic: repeated calls for the same collection URI should deliver the same set of resources. However, this requirement can lead to high memory requirements, so Saxon does not enforce it.
The CollectionFinder
registered with a processor is available to all queries and stylesheets
running under the control of that processor.
Edition
Get the Saxon product edition (for example, "EE" for Enterprise Edition)
ErrorWriter
A TextWriter
used as the destination of miscellaneous error, warning, and progress messages.
By default the Console.Error
is used for all such messages.
A user can supply their own TextWriter
to redirect error messages from the standard output.
Implementation
The underlying Configuration
object in the Saxon implementation
This property provides access to internal methods in the Saxon engine that are not specifically exposed in the .NET API. In general these methods should be considered to be less stable than the classes in the Saxon.Api namespace.
The internal methods follow Java naming conventions rather than .NET conventions.
Information about the returned net.sf.saxon.Configuration object (and the objects it provides access to) is included in the Saxon JavaDoc docmentation.
JProcessor
The underlying net.sf.saxon.s9api.Processor
in the Java implementation
ProductTitle
Get the full name of the Saxon product version implemented by this Processor
ProductVersion
Get the Saxon product version number (for example, "9.2.0.2")
QueryResolver
A user-supplied IQueryResolver
used to resolve location hints appearing in an
import module
declaration.
This acts as the default value for the ModuleURIResolver.
The URI Resolver for XQuery modules. May be null, in which case any existing Module URI Resolver is removed from the Configuration
SchemaManager
Gets the SchemaManager
for the Processor
. Returns null
if the Processor
is not schema-aware.
StandardCollectionFinder
The standard (built-in) collection finder that is used by default if no user-defined
collection finder has been supplied. This is exposed as a property of the Processor
so that it can be invoked by a user-written collection finder.
XmlResolver
An XmlResolver
, which will be used while compiling and running queries,
XPath expressions, and stylesheets, if no other XmlResolver
is nominated
By default an XmlUrlResolver
is used. This means that the responsibility
for resolving and dereferencing URIs rests with the .NET platform, not with the
IKVM/OpenJDK runtime.
When Saxon invokes a user-written XmlResolver
, the GetEntity
method
may return any of: a System.IO.Stream
; a System.IO.TextReader
; or a
java.xml.transform.Source
.
XmlVersion
The XML version used in this Processor
The value must be 1.0 or 1.1, as a decimal
. The default version is currently 1.0, but may
change in the future.
Method Detail
DeclareCollation
CompareInfo compareInfo,
CompareOptions options)
Create a collation based on a given CompareInfo
and CompareOptions
Parameters:
uri
- The collation URI to be used within an XPath expression to refer to this collationcompareInfo
- The CompareInfo
, which determines the language-specific
collation rules to be usedoptions
- Options to be used in performing comparisons, for example
whether they are to be case-blind and/or accent-blindGetMediaTypeForFileExtension
Get the media type to be associated with a file extension by the standard collection handler
Parameters:
extension
- the file extension, for example "xml". The value "" gets
the default media type to be used for unregistered file extensions. The default
media type is also returned if the supplied file extension is not registeredReturns:
GetProperty
Get the value of a configuration property
This method provides the ability to get named properties of the configuration.
The property names are supplied as strings, whose values can be found in the Java
class net.sf.saxon.FeatureKeys
. The property values are always returned as strings.
Properties whose values are other types are returned by converting the value to a
string.
Note that on/off properties are returned using the strings "true" and "false".
Method added in Saxon 9.1
Parameters:
name
- The property nameReturns:
GetProperty
Get a property of the configuration
Parameters:
feature
- the required property. Returns:
NewDocumentBuilder
Create a new DocumentBuilder
, which may be used to build XDM documents from
a variety of sources.
Returns:
DocumentBuilder
NewSerializer
Create a Serializer
initialized to write to a given TextWriter
.
Closing the writer after use is the responsibility of the caller.
Parameters:
textWriter
- The TextWriter
to which the Serializer
will writeReturns:
Serializer
NewSerializer
Create a Serializer
initialized to write to a given output Stream
.
Closing the output stream after use is the responsibility of the caller.
Parameters:
stream
- The output Stream
to which the Serializer
will writeReturns:
NewXPathCompiler
Create a new XPathCompiler
, which may be used to compile XPath expressions.
The returned XPathCompiler
retains a live link to the Processor
, and
may be affected by subsequent changes to the Processor
.
Returns:
XPathCompiler
NewXQueryCompiler
Create a new XQueryCompiler
, which may be used to compile XQuery queries.
The returned XQueryCompiler
retains a live link to the Processor
, and
may be affected by subsequent changes to the Processor
.
Returns:
XQueryCompiler
NewXsltCompiler
Create a new XsltCompiler
, which may be used to compile XSLT stylesheets.
The returned XsltCompiler
retains a live link to the Processor
, and
may be affected by subsequent changes to the Processor
.
Returns:
XsltCompiler
RegisterCollection
IResourceCollection collection)
Register a specific URI and bind it to a specific ResourceCollection
Parameters:
collectionURI
- the collection URI to be registered. Must not be null.collection
- the ResourceCollection to be associated with this URI. Must not be null.RegisterCollection
IEnumerable contents)
Register a named collection. A collection is identified by a URI (the collection URI),
and its content is represented by an IEnumerable
that enumerates the contents
of the collection. The values delivered by this enumeration are Uri values, which
can be mapped to nodes using the registered XmlResolver
.
Collections should be stable: that is, two calls to retrieve the same collection URI should return the same sequence of document URIs. This requirement is imposed by the W3C specifications, but in the case of a user-defined collection it is not enforced by the Saxon product.
A collection may be replaced by specifying the URI of an existing collection.
Collections registered with a processor are available to all queries and stylesheets running under the control of that processor. Collections should not normally be registered while queries and transformations are in progress.
Parameters:
collectionUri
- The URI used to identify the collection in a call
of the XPath collection()
function. The default collection is registered
by supplying null as the value of this argument (this is the collection returned
when the XPath collection()
function is called with no arguments).contents
- An enumerable object that represents the contents of the
collection, as a sequence of document URIs. The enumerator returned by this
IEnumerable object must return instances of the Uri class.RegisterExtensionFunction
Register an extension function with the Processor
Parameters:
function
-
An object that defines the extension function, including its name, arity, arguments
types, and
a reference to the class that implements the extension function call.
RegisterExtensionFunction
Register a simple external/extension function that is to be made available within
any stylesheet, query
or XPath expression compiled under the control of this Processor
Parameters:
function
-
This interface provides only for simple extensions that have no side-effects and no
dependencies on the static or dynamic context.
RegisterFileExtension
Set the media type to be associated with a file extension by the standard collection handler
Parameters:
extension
- the file extension, for exmaple "xml". The value "" sets the
default media type to be used for unregistered file extensionsmediaType
- the corresponding media type, for example "application/xml". The
choice of media type determines how a resource with this extension gets parsed, when
the file
appears as part of a collectionRegisterMediaType
IResourceFactory factory)
Associated a media type with a resource factory. This methodm may be called to customize the behaviour of a collection to recognize different file extensions
Parameters:
contentType
- a media type or MIME type, for example application/xsd+xmlfactory
- a ResourceFactory used to parse (or otherweise process) resource of that typeSetProperty
Set a configuration property
This method provides the ability to set named properties of the configuration.
The property names are set as strings, whose values can be found in the Java
class net.sf.saxon.FeatureKeys
. The property values are always strings.
Properties whose values are other types are not available via this interface:
however all properties have an effective equivalent whose value is a string.
Note that on/off properties are set using the strings "true" and "false".
Method added in Saxon 9.1
Parameters:
name
- The property namevalue
- The property valueSetProperty
T value)
Set a configuration property
Parameters:
feature
- The property featurevalue
- The property valueWriteXdmValue
XmlDestination destination)
Copy an XdmValue
to an XmlDestination
In principle this method can be used to copy any kind of XdmValue
to any kind
of XmlDestination
. However, some kinds of destination may not accept arbitrary
sequences of items; for example, some may reject function items. Some destinations
perform sequence normalization, as defined in the W3C serialization specification,
to convert the supplied sequence to a well-formed XML document; it is a property
of the chosen XmlDestination
whether it does this or not.
Parameters:
sequence
- The value to be writtendestination
- The destination to which the value should be written
Declare a mapping from a specific namespace URI to a .NET class This will get applied to Saxon-PEN or Saxon-EEN product
Parameters:
uri
- the namespace URI of the function nametype
- the .NET class that implements the functions in this namespace