Overview Units Class Hierarchy Classes, Interfaces, Objects and Records Types Variables Constants Functions and Procedures Identifiers |
Interface IXQValue
Unit
xquery
Declaration
type IXQValue = interface(IInterface)
Description
Variant used in XQuery-expressions
This is the base interface used to access the various values occuring during the evaluation of an XQuery expression.
You can read its value with methods like toBoolean, toInt64, toDecimal, toString, toDateTime, toNode, toArray, which convert the returned value to the requested type.
Since IXQValue is an interface, it can be used without worrying much about memory management. So if you have an IXQValue value , you can read it like value.toString or value.toBoolean . Or assign it to another value2 just by writing value2 := value .
An IXQValue can store a sequence of IXQValue -s which can be iterated with a for each loop for valueIterator in valueSequence or using count and get . An IXQValue can also store an object, whose properties can be accessed with getProperty .
IXQValue provides a chainable functional interface with its map, filter, query, retrieve and order methods. These method evaluate an XQuery expression, whereby the current IXQValue is stored in . (for a single value) or $_ (for a sequence of values) For example you can use seq.map('. + 1') to increment all values stored in a sequence seq. Or seq.map('. || "append"') to append a string to all values. Or filter('. >= 10') to drop all values below 10. Or query('reverse($_)') to reverse a sequence. A combined example is query('1 to 10').filter('. mod 2 = 0').map('. * 10').query('sum($_)').toString , which will return 300, the sum of all even numbers times 10.
Retrieve will download and parse the resource referenced in this IXQValue . For example query('"http://example.org"').retrieve().map('//title') to get the title of a webpage.
IXQValue are usually returned by the evaluation of a query, so you don't have to create your own, but if you want, you can use the xqvalue() functions which return a IXQValue corresponding to the type of their parameter.
You can declare user defined types by deriving TXQValue (not IXQValue , there is a bunch of staff depending on the class).
Each value is a tuple of the value of a Pascal type (e.g. string, int64, double, bigdecimal), and an XML schema type annotation.
There are different ways to check which type an IXQValue has:
The method code(typeAnnotation) returns the logical type of the value, i.e. the type seen by an XQuery expression. This is an object in a @noLink(schema) describing the type (e.g. name "xs:string", ranges), and does not necessary correspond to the type used to store the value.
A derivation check is TXQValue... . This checks if the value is stored in a certain implementation class (e.g. TXQValueString)
The method kind returns the kind of the value, an enum corresponding to each of the implementation base classes, e.g. pvkString
Hierarchy
Overview
Methods
Properties
Description
Methods
|
function typeName: string; |
XPath type name
|
|
function typeAnnotation: TXSType; |
Returns the class underlying the interface
|
|
function isUndefined: boolean; |
Returns true, iff the value is undefined or an empty sequence
|
|
function toBoolean: boolean; |
Returns the value as boolean; dynamically converted, if necessary
|
|
function toBooleanEffective: boolean; |
Returns the effective boolean value, as defined in XPath. (the main difference to toBoolean is that toBooleanEffective returns true for the string "false", while toBoolean returns false)
|
|
function toInt64: int64; |
Returns the value as int64; dynamically converted, if necessary
|
|
function toFloat: xqfloat; |
Returns the value as xqfloat (double); dynamically converted, if necessary
|
|
function toDecimal: BigDecimal; |
Returns the value as bigdecimal; dynamically converted, if necessary
|
|
function toString: string; |
Returns the value as string; dynamically converted, if necessary
|
|
function toJoinedString(const sep: string=' '): string; |
Returns the value as joined string (string-join($self, $sep)); dynamically converted, if necessary
|
|
function toDateTime: TDateTime; |
Returns the value as dateTime; dynamically converted, if necessary
|
|
function toNode: TTreeNode; |
Returns the value as node; or nil if it is no node
|
|
function toArray: TXQVArray; |
Returns the value as array; dynamically converted, if necessary. If the value is a single element, the array contains that element; if it is a sequence, the array contains each element of the sequence
|
|
function toXQVList: TXQVList; |
Returns a TXQVList of all values contained in the implicit sequence. (if the type is not a sequence, it is considered to be a single element sequence). (this list is not an interface, don't forget to free it! This is the only interface method returning a non-auto-freed value.)
|
|
function toXQuery: string; |
Converts the value to an XQuery expression that evaluates to an equal value again (intended for debugging, not serialization, so no guarantees)
|
|
function getSequenceCount: integer; |
Returns the number of values actually contained in this value (0 for undefined, element count for sequences, and 1 for everything else)
|
|
function get(i: integer): IXQValue; |
Returns the i-th value in this sequence. (non-sequence values are considered to be sequences of length 1) (1-based index)
|
|
function getProperty(const name: string): IXQValue; |
Returns an object property. Returns empty sequence for non objects.
|
|
function getPropertyEnumerator: TXQValuePropertyEnumerator; |
Returns an iterator over all object properties. Raises an exception for non-objects
|
|
function debugAsStringWithTypeAnnotation(textOnly: boolean = true): string; deprecated 'use toXQuery'; |
Warning: this symbol is deprecated: use toXQuery
Returns the value of this value, annotated with its type (e.g. string: abc)
|
|
function jsonSerialize(nodeFormat: TTreeNodeSerialization; insertWhitespace: boolean = false; const indent: string = ''): string; |
Returns a json representation of this value. Converting sequences to arrays and objects to objects
|
|
function xmlSerialize(nodeFormat: TTreeNodeSerialization; sequenceTag: string = 'seq'; elementTag: string = 'e'; objectTag: string = 'object'): string; |
Returns a xml representation of this value
|
|
function clone: IXQValue; |
Returns a clone of this value (deep copy). It is also an ref-counted interface, but can be safely be modified without affecting possible other references.
|
|
function GetEnumerator: TXQValueEnumerator; |
Implements the enumerator for for..in. Because it returns an IXQValue, it modifies the reference count of all objects in the sequence. For large sequences this is rather slow (e.g. it wastes 1 second to iterate over 10 million values in a simple benchmark.) and it is recommended to use GetEnumeratorPtrUnsafe. (it took 35ms for those 10 million values, comparable to the 30ms of a native loop not involving any enumerators)
|
|
function GetEnumeratorPtrUnsafe: TXQValueEnumeratorPtrUnsafe; |
Implements a faster version of GetEnumerator. It does not change any reference counts, not even of self, so it must not be used with values returned by functions!
|
|
function query(const q: string): IXQValue; |
Evaluates another XQuery expression on this value using the defaultQueryEngine. The return value is query whereby self is stored in $_. Use this to do an operation on all values of a sequence, e.g. sum($_)
|
|
function query(const q: string; const vs: array of ixqvalue): IXQValue; |
Like query, sets the additional arguments as variables $_1, $_2, ...
|
|
function query(const q: string; const vs: array of string): IXQValue; |
Like query , sets the additional arguments as variables $_1, $_2, ...
|
|
function map(const q: string): IXQValue; |
Evaluates another XQuery expression on this value using the defaultQueryEngine. The return value is self ! query (i.e. all values in self simply mapped through query)
|
|
function map(const q: string; const vs: array of ixqvalue): IXQValue; |
Like map, sets the additional arguments as variables $_1, $_2, ...
|
|
function map(const q: string; const vs: array of string): IXQValue; |
Like map , sets the additional arguments as variables $_1, $_2, ...
|
|
function filter(const q: string): IXQValue; |
Evaluates another XQuery expression on this value using the defaultQueryEngine. The return value is self [query] (i.e. all values in self filtered through query)
|
|
function filter(const q: string; const vs: array of ixqvalue): IXQValue; |
Like filter, sets the additional arguments as variables $_1, $_2, ...
|
|
function filter(const q: string; const vs: array of string): IXQValue; |
Like filter , sets the additional arguments as variables $_1, $_2, ...
|
|
function order(const q: string = '$_'): IXQValue; |
Orders the sequence, equivalent to query for $_ in self order by (....) return $_ . The current value is in $_. Append ascending or descending to set the sorting direction. Kind of slow
|
|
function retrieve(): IXQValue; |
Retrieves referenced resources. This is primarily used for HTTP requests, but can also retrieve files. It will parse the resource as HTML/XML/JSON if possible. It will retrieve each value in a sequence individually
|
|
function instanceOf(const typ: TXSType): boolean; |
If the XPath expression "self instance of typ" should return true. (abbreviation for typeAnnotation.derivedFrom(..) )
|
Properties
Generated by PasDoc 0.14.0.
|