Saxon.Api

 

 

Saxon.Api

Class XdmAtomicValue


public class XdmAtomicValue
extends XdmItem

The class XdmAtomicValue represents an item in an XDM sequence that is an atomic value. The value may belong to any of the 19 primitive types defined in XML Schema, or to a type derived from these primitive types, or to the XDM-specific type xs:untypedAtomic.

Note that there is no guarantee that every XdmValue comprising a single atomic value will be an instance of this class. To force this, use the Simplify property of the XdmValue.

Constructor Summary

XdmAtomicValue (net.sf.saxon.value.AtomicValue atomicValue)

Construct an XdmNode as a wrapper around an instance of the internal class Saxon.Hej.value.AtomicValue

XdmAtomicValue (string str)

Construct an atomic value of type xs:string

XdmAtomicValue (long i)

Construct an atomic value of type xs:integer from a supplied long

XdmAtomicValue (int i)

Construct an atomic value of type xs:integer from a supplied long

XdmAtomicValue (Byte i)

Construct an atomic value of type xs:integer from a supplied byte

XdmAtomicValue (decimal d)

Construct an atomic value of type xs:decimal

XdmAtomicValue (float f)

Construct an atomic value of type xs:float

XdmAtomicValue (DateTime dt)

Construct an atomic value of type xs:dateTime from a .NET DateTime object. The timezone offset in the result is taken from the system clock: more specifically, it is the value of TimeZoneInfo.Local.GetUtcOffset(DateTime.Now)

XdmAtomicValue (DateTimeOffset offset)

Construct an atomic value of type xs:dateTime with a specific timezone offset from a DateTimeOffset object.

XdmAtomicValue (double d)

Construct an atomic value of type xs:double

XdmAtomicValue (bool b)

Construct an atomic value of type xs:boolean

XdmAtomicValue (Uri u)

Construct an atomic value of type xs:anyURI

XdmAtomicValue (QName q)

Construct an atomic value of type xs:QName

XdmAtomicValue (string lexicalForm, XdmAtomicType type)

Construct an atomic value of a given type

 

Property Summary

 QName PrimitiveTypeName

Get the name of the primitive type of the value

 QName TypeName

Get the name of the value's XDM type

 object Value

Get the value as a CLI object of the nearest equivalent type.

 

Method Summary

 bool AsBoolean ()

Get the value converted to a boolean using the XPath casting rules.

 decimal AsDecimal ()

Get the value converted to a decimal using the XPath casting rules.

 double AsDouble ()

Get the value converted to a double using the XPath casting rules.

 long AsLong ()

Get the value converted to a long using the XPath casting rules.

 QName AsQName ()

Get the value converted to a QName. The value must be of type xs:QName or xs:NOTATION.

 bool Equals (object other)

Compare two atomic values for equality

 int GetHashCode ()

Get a hash code to support equality comparison

 bool IsAtomic ()

Determine whether the item is an atomic value

static XdmAtomicValue MakeAtomicValue (object value)

Create an atomic value of a type appropriate to the supplied value.

 string ToString ()

Convert the atomic value to a string

 

Constructor Detail

XdmAtomicValue

public XdmAtomicValue(net.sf.saxon.value.AtomicValue atomicValue)

Construct an XdmNode as a wrapper around an instance of the internal class Saxon.Hej.value.AtomicValue

Applications using the class Saxon.Hej.value.AtomicValue should be aware that it is subject to occasional changes from one release to the next. For documentation on this class, see the Saxon-EE Javadoc documentation for the very similar class net.sf.saxon.value.AtomicValue.

Parameters:

atomicValue - The object to be wrapped

XdmAtomicValue

public XdmAtomicValue(string str)

Construct an atomic value of type xs:string

Parameters:

str - The string value

XdmAtomicValue

public XdmAtomicValue(long i)

Construct an atomic value of type xs:integer from a supplied long

Parameters:

i - The integer value

XdmAtomicValue

public XdmAtomicValue(int i)

Construct an atomic value of type xs:integer from a supplied long

Parameters:

i - The integer value

XdmAtomicValue

public XdmAtomicValue(Byte i)

Construct an atomic value of type xs:integer from a supplied byte

Parameters:

i - The integer value, in the range -128 to +127

XdmAtomicValue

public XdmAtomicValue(decimal d)

Construct an atomic value of type xs:decimal

Parameters:

d - The decimal value

XdmAtomicValue

public XdmAtomicValue(float f)

Construct an atomic value of type xs:float

Parameters:

f - The float value

XdmAtomicValue

public XdmAtomicValue(DateTime dt)

Construct an atomic value of type xs:dateTime from a .NET DateTime object. The timezone offset in the result is taken from the system clock: more specifically, it is the value of TimeZoneInfo.Local.GetUtcOffset(DateTime.Now)

Parameters:

dt - The DateTime object value

XdmAtomicValue

public XdmAtomicValue(DateTimeOffset offset)

Construct an atomic value of type xs:dateTime with a specific timezone offset from a DateTimeOffset object.

Parameters:

offset - The DateTimeOffset value

XdmAtomicValue

public XdmAtomicValue(double d)

Construct an atomic value of type xs:double

Parameters:

d - The double value

XdmAtomicValue

public XdmAtomicValue(bool b)

Construct an atomic value of type xs:boolean

Parameters:

b - The boolean value

XdmAtomicValue

public XdmAtomicValue(Uri u)

Construct an atomic value of type xs:anyURI

Parameters:

u - The uri value

XdmAtomicValue

public XdmAtomicValue(QName q)

Construct an atomic value of type xs:QName

Parameters:

q - The QName value

XdmAtomicValue

public XdmAtomicValue(string lexicalForm,
                      XdmAtomicType type)

Construct an atomic value of a given type

Parameters:

lexicalForm - The string representation of the value (any value that is acceptable in the lexical space, as defined by XML Schema Part 2). Whitespace normalization as defined by the target type will be applied to the value.
type - The type given as an XdmAtomicType

Property Detail

PrimitiveTypeName

public QName PrimitiveTypeName {get; }

Get the name of the primitive type of the value

Returns:

The primitive type of the value, as a QName. This will be the name of one of the primitive types defined in XML Schema Part 2, or the XPath-defined type xs:untypedAtomic. For the purposes of this method, xs:integer is considered to be a primitive type.

TypeName

public QName TypeName {get; }

Get the name of the value's XDM type

Returns:

The type of the value, as a QName.

Value

public object Value {get; }

Get the value as a CLI object of the nearest equivalent type.

The return type is as follows:

  • xs:string - String
  • xs:integer - Long
  • xs:decimal - Decimal
  • xs:double - Double
  • xs:float - Float
  • xs:boolean - Bool
  • xs:QName - QName
  • xs:anyURI - Uri
  • xs:untypedAtomic - String
  • wrapped external object - the original external object
  • Other types - currently String, but this may change in the future

Returns:

The value converted to the most appropriate CLI type

Method Detail

AsBoolean

public bool AsBoolean()
throws
InvalidCastException

Get the value converted to a boolean using the XPath casting rules.

Returns:

The result of converting to a boolean (Note: this is not the same as the effective boolean value).

Throws:

InvalidCastException - If the value cannot be cast to an xs:boolean

AsDecimal

public decimal AsDecimal()
throws
InvalidCastException

Get the value converted to a decimal using the XPath casting rules.

Returns:

The result of converting to a decimal

Throws:

InvalidCastException - If the value cannot be cast to an xs:decimal, or converted to a .NET primitive decimal.

AsDouble

public double AsDouble()
throws
InvalidCastException

Get the value converted to a double using the XPath casting rules.

If the value is a string, the XSD 1.1 rules are used, which means that the string "+INF" is recognised.

Returns:

The result of converting to a double

Throws:

InvalidCastException - If the value cannot be cast to an xs:double

AsLong

public long AsLong()
throws
InvalidCastException

Get the value converted to a long using the XPath casting rules.

Returns:

The result of converting to a long

Throws:

InvalidCastException - If the value cannot be cast to an xs:long

AsQName

public QName AsQName()
throws
InvalidCastException

Get the value converted to a QName. The value must be of type xs:QName or xs:NOTATION.

Returns:

The result of converting to a QName

Throws:

InvalidCastException - If the value cannot be cast to an xs:QName

Equals

public override bool Equals(object other)

Compare two atomic values for equality

Parameters:

other - The object to be compared

Returns:

The result of the equality comparison, using the rules of the op:is-same-key() comparison used for comparing key values in maps.

GetHashCode

public override int GetHashCode()

Get a hash code to support equality comparison

Returns:

A suitable hash code

IsAtomic

public override bool IsAtomic()

Determine whether the item is an atomic value

Returns:

True (the item is an atomic value).

MakeAtomicValue

public static XdmAtomicValue MakeAtomicValue(object value)
throws
ArgumentException

Create an atomic value of a type appropriate to the supplied value.

The supplied value must be one of the following:

  • An instance of the Saxon Java class Saxon.Hej.value.AtomicValue
  • A Boolean - returns an instance of xs:boolean
  • A (signed) int, long, short, or byte - returns an instance of xs:integer
  • A Char - TODO ???????
  • A String - returns an instance of xs:string
  • A Double - returns an instance of xs:double
  • A Float - returns an instance of xs:float
  • A decimal - returns an instance of xs:decimal
  • A URI - returns an instance of xs:anyURI
  • A QName - returns an instance of xs:QName

Parameters:

value - The value to be converted.

Returns:

The converted value

Throws:

ArgumentException - If the supplied value is not one of the recognized types

ToString

public override string ToString()

Convert the atomic value to a string

Returns:

The value converted to a string, according to the rules of the XPath cast expression. The result is the same as the StringValue property.