Show / Hide Table of Contents

Class XmlHelper

This abstract class contains XML manipulation methods.

Inheritance
object
XmlHelper
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Tangosol.Run.Xml
Assembly: Coherence.dll
Syntax
public abstract class XmlHelper

Fields

POWER_0

An exponent of zero.

Declaration
public const int POWER_0 = 0
Field Value
Type Description
int

POWER_G

An exponent of 30.

Declaration
public const int POWER_G = 30
Field Value
Type Description
int

POWER_K

An exponent of 10.

Declaration
public const int POWER_K = 10
Field Value
Type Description
int

POWER_M

An exponent of 20.

Declaration
public const int POWER_M = 20
Field Value
Type Description
int

POWER_T

An exponent of 40.

Declaration
public const int POWER_T = 40
Field Value
Type Description
int

UNIT_D

A unit of days.

Declaration
public const int UNIT_D = 86400000
Field Value
Type Description
int

UNIT_H

A unit of hours.

Declaration
public const int UNIT_H = 3600000
Field Value
Type Description
int

UNIT_M

A unit of minutes.

Declaration
public const int UNIT_M = 60000
Field Value
Type Description
int

UNIT_MS

A unit of milliseconds.

Declaration
public const int UNIT_MS = 1
Field Value
Type Description
int

UNIT_S

A unit of seconds.

Declaration
public const int UNIT_S = 1000
Field Value
Type Description
int

UNRESOLVED

A constant that indicates that the parameter cannot be resolved.

Declaration
public static readonly object UNRESOLVED
Field Value
Type Description
object

Methods

AddElements(IXmlElement, IEnumerator)

Add the elements from the IEnumerator to the passed XML.

Declaration
public static void AddElements(IXmlElement xml, IEnumerator enumerator)
Parameters
Type Name Description
IXmlElement xml

An IXmlElement object to add to.

IEnumerator enumerator

An IEnumerator of zero or more IXmlElement objects to add.

Convert(object, XmlValueType)

Convert the passed object to the specified type.

Declaration
public static object Convert(object o, XmlValueType type)
Parameters
Type Name Description
object o

The object value or null.

XmlValueType type

The enumerated type to convert to.

Returns
Type Description
object

An object of the specified type.

ConvertDocument(XmlDocument)

Converts specified System.Xml.XmlDocument into IXmlDocument.

Declaration
public static IXmlDocument ConvertDocument(XmlDocument xmlDoc)
Parameters
Type Name Description
XmlDocument xmlDoc

Source XmlDocument.

Returns
Type Description
IXmlDocument

IXmlDocument that is the result of conversion.

ConvertElement(XmlElement, IXmlElement, IXmlElement)

Converts specified System.Xml.XmlElement into IXmlElement.

Declaration
public static void ConvertElement(XmlElement source, IXmlElement target, IXmlElement parent)
Parameters
Type Name Description
XmlElement source

Source XmlDocument; must not be null.

IXmlElement target

IXmlElement that will be the result of conversion. If it is null, new instance of IXmlElement will be created.

IXmlElement parent

Parent of target IXmlElement; may be null.

Exceptions
Type Condition
ArgumentNullException

If source is null.

CreateDelegate<TDel>(IXmlElement)

Creates a delegate from a given configuration. IXmlElement of the following structure:

$lt;delegate>
   <static/> | <instance/>
   <class-name></class-name>
   <delegate-type></delegate-type>
   <method-name></method-name>
</delegate>
Declaration
public static TDel CreateDelegate<TDel>(IXmlElement xmlDelegate) where TDel : class
Parameters
Type Name Description
IXmlElement xmlDelegate

The XML element that contains the instantiation info.

Returns
Type Description
TDel

A delegate obtained by the XML configutation

Type Parameters
Name Description
TDel

The type of the delegate.

CreateInstance(IXmlElement, IParameterResolver)

Create an instance of the class configured using an IXmlElement of the following structure:

<!ELEMENT ... (class-name | (class-factory-name, method-name),
init-params?>
<!ELEMENT init-params (init-param*)>
<!ELEMENT init-param ((param-name | param-type), param-value,
description?)>

As of Coherence 12.1.2 the supplied element may also be of the following format:

<!ELEMENT instance>

where the "instance" format is the same as above.

Declaration
public static object CreateInstance(IXmlElement xmlClass, XmlHelper.IParameterResolver resolver)
Parameters
Type Name Description
IXmlElement xmlClass

The XML element that contains the instantiation info.

XmlHelper.IParameterResolver resolver

An XmlHelper.IParameterResolver to resolve "{macro}" values (optional).

Returns
Type Description
object

An object intantiated or obtained based on the class configuration.

CreateInstance(IXmlElement, IParameterResolver, Type)

Create an instance of the class configured using an IXmlElement of the following structure:

<!ELEMENT ... (class-name | (class-factory-name, method-name),
init-params?>
<!ELEMENT init-params (init-param*)>
<!ELEMENT init-param ((param-name | param-type), param-value,
description?)>

As of Coherence 12.1.2 the supplied element may also be of the following format:

<!ELEMENT instance>

where the "instance" format is the same as above.

Declaration
public static object CreateInstance(IXmlElement xmlClass, XmlHelper.IParameterResolver resolver, Type typeAssignable)
Parameters
Type Name Description
IXmlElement xmlClass

The XML element that contains the instantiation info.

XmlHelper.IParameterResolver resolver

An XmlHelper.IParameterResolver to resolve "{macro}" values (optional).

Type typeAssignable

if non-null, this method will validate that the Type is assignable from the loaded Type

Returns
Type Description
object

An object intantiated or obtained based on the class configuration.

DecodeAttribute(string)

Decode an attribute value that was quoted.

Declaration
public static string DecodeAttribute(string value)
Parameters
Type Name Description
string value

The attribute value to decode.

Returns
Type Description
string

The attribute value in its decoded form.

DecodeContent(string)

Decode an element's content value.

Declaration
public static string DecodeContent(string value)
Parameters
Type Name Description
string value

The content value to decode.

Returns
Type Description
string

The attribute value in its decoded form.

DecodeUri(string)

Decode a System Identifier as per the XML 1.0 Specification 2nd ed section 4.2.2.

Declaration
public static string DecodeUri(string uri)
Parameters
Type Name Description
string uri

The URI to decode.

Returns
Type Description
string

The decoded URI.

EncodeAttribute(string, char)

Encode an attribute value so that it can be quoted and made part of a valid and well formed XML document.

Declaration
public static string EncodeAttribute(string value, char chQuote)
Parameters
Type Name Description
string value

The attribute value to encode.

char chQuote

The character that will be used to quote the attribute.

Returns
Type Description
string

The attribute value in its encoded form (but not quoted).

EncodeContent(string, bool)

Encode an element's content value so that it can be made part of a valid and well formed XML document.

Declaration
public static string EncodeContent(string value, bool preferBlockEscape)
Parameters
Type Name Description
string value

The content value to encode.

bool preferBlockEscape

Pass true to use the CDATA escape if two conditions are met: that escaping is required, and that the value does not contain the string "]]>".

Returns
Type Description
string

The attribute value in its encoded form (but not quoted).

EncodeUri(string)

Encode a System Identifier as per the XML 1.0 Specification second edition, section 4.2.2.

Declaration
public static string EncodeUri(string uri)
Parameters
Type Name Description
string uri

The URI to encode.

Returns
Type Description
string

The encoded URI.

EnsureElement(IXmlElement, string)

Ensure that a child element exists.

Declaration
public static IXmlElement EnsureElement(IXmlElement xml, string path)
Parameters
Type Name Description
IXmlElement xml

An XML element.

string path

Element path.

Returns
Type Description
IXmlElement

The existing or new IXmlElement object.

Remarks

If any part of the path does not exist create new child elements to match the path.

Exceptions
Type Condition
ArgumentException

If the name is null or if any part of the path is not a legal XML tag name.

InvalidOperationException

If any element in the path is immutable or otherwise can not add a child element.

See Also
FindElement(IXmlElement, string)

EnsureNamespace(IXmlElement, string, string)

Ensure the existence of the Namespace declaration attribute in a context of the specified IXmlElement.

Declaration
public static void EnsureNamespace(IXmlElement xml, string prefix, string uri)
Parameters
Type Name Description
IXmlElement xml

The IXmlElement.

string prefix

The Namespace prefix.

string uri

The Namespace URI.

EqualsElement(IXmlElement, IXmlElement)

Compare one XML element with another XML element for equality.

Declaration
public static bool EqualsElement(IXmlElement xml1, IXmlElement xml2)
Parameters
Type Name Description
IXmlElement xml1

A non-null IXmlElement object.

IXmlElement xml2

A non-null IXmlElement object.

Returns
Type Description
bool

true if the elements are equal, false otherwise.

EqualsValue(IXmlValue, IXmlValue)

Compare one XML value with another XML value for equality.

Declaration
public static bool EqualsValue(IXmlValue val1, IXmlValue val2)
Parameters
Type Name Description
IXmlValue val1

A non-null IXmlValue object.

IXmlValue val2

A non-null IXmlValue object.

Returns
Type Description
bool

true if the values are equal, false otherwise.

FindElement(IXmlElement, string)

Find a child element with the specified '/'-delimited path.

Declaration
public static IXmlElement FindElement(IXmlElement xml, string path)
Parameters
Type Name Description
IXmlElement xml

An IXmlElement.

string path

The path to follow to find the desired XML element.

Returns
Type Description
IXmlElement

The child element with the specified path or null if such a child element does not exist.

Remarks

The path format is based on a subset of the XPath specification, supporting:

  • Leading '/' to specify root
  • Use of '/' as a path delimiter
  • Use of '..' to specify parent
If multiple child elements exist that have the specified name, then the behavior of this method is undefined, and it is permitted to return any one of the matching elements, to return null, or to throw an arbitrary runtime exception.

FindElement(IXmlElement, string, object)

Find a child element with the specified '/'-delimited path and the specified value.

Declaration
public static IXmlElement FindElement(IXmlElement xml, string path, object value)
Parameters
Type Name Description
IXmlElement xml

An IXmlElement.

string path

The path to follow to find the desired XML element.

object value

The value to match.

Returns
Type Description
IXmlElement

The child element with the specified path and value or null if the such a child element does not exist.

Remarks

The path format is based on a subset of the XPath specification, supporting:

  • Leading '/' to specify root
  • Use of '/' as a path delimiter
  • Use of '..' to specify parent
If multiple child elements exist that have the specified name and value, then this method returns any one of the matching elements.

GetAbsolutePath(IXmlElement)

Get the '/'-delimited path of the passed element starting from the root element.

Declaration
public static string GetAbsolutePath(IXmlElement xml)
Parameters
Type Name Description
IXmlElement xml

An IXmlElement.

Returns
Type Description
string

The path to the passed element in "absolute" format.

GetAttribute(IXmlElement, string, string)

Get an attribute of the specified IXmlElement that matches to the specified local name and the specified Namespace URI.

Declaration
public static IXmlValue GetAttribute(IXmlElement xml, string local, string uri)
Parameters
Type Name Description
IXmlElement xml

The IXmlElement.

string local

The local attribute name.

string uri

The Namespace URI.

Returns
Type Description
IXmlValue

An IXmlValue that matches to the specified local name and the specified Namespace URI.

GetElement(IXmlElement, string)

Get a child element for the specified element.

Declaration
public static IXmlElement GetElement(IXmlElement xml, string name)
Parameters
Type Name Description
IXmlElement xml

An IXmlElement.

string name

The name of the desired child element.

Returns
Type Description
IXmlElement

The specified element as an object implementing IXmlElement, or null if the specified child element does not exist.

Remarks

If multiple child elements exist that have the specified name, then the behavior of this method is undefined, and it is permitted to return any one of the matching elements, to return null, or to throw an arbitrary runtime exception.

GetElement(IXmlElement, string, string)

Get a child element of the specified IXmlElement that matches to the specified local name and the specified Namespace URI.

Declaration
public static IXmlElement GetElement(IXmlElement xml, string local, string uri)
Parameters
Type Name Description
IXmlElement xml

The parent IXmlElement.

string local

The local xml name.

string uri

The Namespace URI.

Returns
Type Description
IXmlElement

An element that matches to the specified local name and the specified Namespace URI.

GetElements(IXmlElement, string, string)

Get an IEnumerator of child elements of the specified IXmlElement that match to the specified local name and the specified Namespace URI.

Declaration
public static IEnumerator GetElements(IXmlElement xml, string local, string uri)
Parameters
Type Name Description
IXmlElement xml

The parent IXmlElement.

string local

The local xml name.

string uri

The Namespace URI.

Returns
Type Description
IEnumerator

An IEnumerator containing all matching child elements.

GetNamespacePrefix(IXmlElement, string)

Retrieve the Namespace prefix for a given URI in a context of the specified IXmlElement.

Declaration
public static string GetNamespacePrefix(IXmlElement xml, string uri)
Parameters
Type Name Description
IXmlElement xml

The IXmlElement.

string uri

The Namespace URI.

Returns
Type Description
string

The Namespace prefix corresponding to the URI.

GetNamespaceUri(IXmlElement, string)

Retrieve the Namespace URI for a given prefix in a context of the specified IXmlElement.

Declaration
public static string GetNamespaceUri(IXmlElement xml, string prefix)
Parameters
Type Name Description
IXmlElement xml

The IXmlElement.

string prefix

The Namespace prefix.

Returns
Type Description
string

The Namespace URI corresponding to the prefix.

GetUniversalName(string, string)

Return a universal XML element name.

Declaration
public static string GetUniversalName(string local, string prefix)
Parameters
Type Name Description
string local

The local XML element name.

string prefix

The Namespace prefix.

Returns
Type Description
string

The universal XML element name.

See Also
http://www.jclark.com/xml/xmlns.htm

HashElement(IXmlElement)

Provide a hash value for the XML element and all of its contained information.

Declaration
public static int HashElement(IXmlElement xml)
Parameters
Type Name Description
IXmlElement xml

The IXmlElement.

Returns
Type Description
int

The hash value for the XML element.

Remarks

The hash value is defined as a xor of the following:

  • the GetHashCode() from the element's value (i.e. base.GetHashCode())
  • the GetHashCode() from each attribute name
  • the GetHashCode() from each attribute value
  • the GetHashCode() from each sub-element

HashValue(IXmlValue)

Provide a hash value for the XML value.

Declaration
public static int HashValue(IXmlValue val)
Parameters
Type Name Description
IXmlValue val

The IXmlValue.

Returns
Type Description
int

The hash value for the XML value.

Remarks

The hash value is defined as one of the following:

  1. 0 if Value returns null
  2. otherwise the hash value is the GetHashCode() of the string representation of the value

IsCommentValid(string)

Validate the passed comment.

Declaration
public static bool IsCommentValid(string comment)
Parameters
Type Name Description
string comment

The XML comment.

Returns
Type Description
bool

true if the comment is valid, false otherwise.

Remarks

Comments may not contain "--". See the XML specification 1.0 2ed section 2.5.

IsElementMatch(IXmlElement, string, string)

Check whether or not an element matches to the specified local name and Namespace URI.

Declaration
public static bool IsElementMatch(IXmlElement xml, string local, string uri)
Parameters
Type Name Description
IXmlElement xml

The IXmlElement

string local

The local xml name.

string uri

The Namespace URI.

Returns
Type Description
bool

true if the specified element matches to the specified local name and the specified Namespace URI.

IsEmpty(IXmlElement)

Check whether or not this element or any of its children elements have any content such as values or attributes.

Declaration
public static bool IsEmpty(IXmlElement xml)
Parameters
Type Name Description
IXmlElement xml

An IXmlElement.

Returns
Type Description
bool

true iff the element itself and all of its children have neither values nor attributes.

IsEncodingValid(string)

Validate the passed encoding.

Declaration
public static bool IsEncodingValid(string encoding)
Parameters
Type Name Description
string encoding

The document encoding.

Returns
Type Description
bool

true if the encoding is valid, false otherwise.

Remarks

Encodings are lating strings defined as: [A-Za-z] ([A-Za-z0-9._] | '-')*

IsInstanceConfigEmpty(IXmlElement)

Check whether or not the specified configuration defines an instance of a class.

Declaration
public static bool IsInstanceConfigEmpty(IXmlElement xmlClass)
Parameters
Type Name Description
IXmlElement xmlClass

The XML element that contains the instantiation info.

Returns
Type Description
bool

true iff there is no class configuration information available.

Remarks

The specified IXmlElement shoud be of the same structure as used in the CreateInstance(IXmlElement, IParameterResolver).

IsNameMatch(IXmlElement, string, string, string)

Check whether or not a universal (composite) name matches to the specified local name and Namespace URI.

Declaration
public static bool IsNameMatch(IXmlElement xml, string name, string local, string uri)
Parameters
Type Name Description
IXmlElement xml

The (context) IXmlElement.

string name

The universal name.

string local

The local xml name.

string uri

The Namespace URI.

Returns
Type Description
bool

true if the specified element matches to the specified local name and the specified Namespace URI.

IsNameValid(string)

Validate the passed name.

Declaration
public static bool IsNameValid(string name)
Parameters
Type Name Description
string name

The XML name to validate.

Returns
Type Description
bool

true if the name is valid, false otherwise.

Remarks

Currently, this does not allow the "CombiningChar" or "Extender" characters that are allowed by the XML specification 1.0 2ed section 2.3 [4].

IsPublicIdentifierValid(string)

Validate the passed public identifier.

Declaration
public static bool IsPublicIdentifierValid(string name)
Parameters
Type Name Description
string name

The public identifier of the XML document.

Returns
Type Description
bool

true if the identifier is valid, false otherwise.

IsSystemIdentifierValid(string)

Validate the passed system identifier.

Declaration
public static bool IsSystemIdentifierValid(string name)
Parameters
Type Name Description
string name

The system identifier of the XML document.

Returns
Type Description
bool

true if the identifier is valid, false otherwise.

IsWhitespace(char)

Test if the specified character is XML whitespace.

Declaration
public static bool IsWhitespace(char ch)
Parameters
Type Name Description
char ch

A character.

Returns
Type Description
bool

true if the passed character is XML whitespace.

LoadResource(IResource, string)

Load an XML configuration from a resource.

Declaration
public static IXmlDocument LoadResource(IResource resource, string description)
Parameters
Type Name Description
IResource resource

The resource.

string description

A description of the resource being loaded (e.g. "cache configuration"). The description is only used in logging and error messages related to loading the resource.

Returns
Type Description
IXmlDocument

The configuration XML.

LoadXml(Stream)

Load XML from a stream.

Declaration
public static IXmlDocument LoadXml(Stream stream)
Parameters
Type Name Description
Stream stream

The Stream object.

Returns
Type Description
IXmlDocument

The XML content.

LoadXml(Stream, Encoding)

Load XML from a stream using the specified encoding.

Declaration
public static IXmlDocument LoadXml(Stream stream, Encoding encoding)
Parameters
Type Name Description
Stream stream

The Stream object.

Encoding encoding

Encoding.

Returns
Type Description
IXmlDocument

The XML content.

LoadXml(TextReader)

Load XML from a reader.

Declaration
public static IXmlDocument LoadXml(TextReader reader)
Parameters
Type Name Description
TextReader reader

The TextReader object.

Returns
Type Description
IXmlDocument

The XML content.

LoadXml(string)

Load XML from a resource specified by path.

Declaration
public static IXmlDocument LoadXml(string path)
Parameters
Type Name Description
string path

Location of Xml data; an URL or valid path.

Returns
Type Description
IXmlDocument

The XML content.

LoadXml(IResource)

Load XML from a given IResource.

Declaration
public static IXmlDocument LoadXml(IResource resource)
Parameters
Type Name Description
IResource resource

The resource.

Returns
Type Description
IXmlDocument

The XML content.

LookupXmlValueType(string)

Convert a string type to known XmlValueTypes, if any.

Declaration
public static XmlValueType LookupXmlValueType(string type)
Parameters
Type Name Description
string type

the type to lookup.

Returns
Type Description
XmlValueType

The corresponding XmlValueType or null if no match exists.

OverrideElement(IXmlElement, IXmlElement)

Override the values of the specified base element with values from the specified override element.

Declaration
public static void OverrideElement(IXmlElement xmlBase, IXmlElement xmlOverride)
Parameters
Type Name Description
IXmlElement xmlBase

Base IXmlElement.

IXmlElement xmlOverride

Override IXmlElement.

Remarks

The values are only overriden if there is an exact match between the element paths and all attribute values. Empty override values are ignored. Override elements that do not match any of the base elements are just copied over. No ambiguity is allowed.
For example, if the base element has more then one child with the same name and attributes then the override is not allowed.

Exceptions
Type Condition
InvalidOperationException

If the base element is immutable or there is ambiguity between the override and base elements.

OverrideElement(IXmlElement, IXmlElement, string)

Override the values of the specified base element with values from the specified override element.

Declaration
public static void OverrideElement(IXmlElement xmlBase, IXmlElement xmlOverride, string idAttrName)
Parameters
Type Name Description
IXmlElement xmlBase

Base IXmlElement.

IXmlElement xmlOverride

Override IXmlElement.

string idAttrName

Attribute name that serves as an identifier allowing to match elements with the same name; if not specified all attributes have to match for an override.

Remarks

The values are only overriden if there is an exact match between the element paths and an attribute value for the specified attribute name. Empty override values are ignored. Override elements that do not match any of the base elements are just copied over. No ambiguity is allowed.
For example, if the base element has more then one child with the same name and the specified attribute's value then the override is not allowed.

Exceptions
Type Condition
InvalidOperationException

If the base element is immutable or there is ambiguity between the override and base elements.

ParseInitParams(IXmlElement)

Parse the specified "init-params" element of the following structure:

<!ELEMENT init-params (init-param*)>
<!ELEMENT init-param ((param-name | param-type), param-value,
description?)>

into an object array.

Declaration
public static object[] ParseInitParams(IXmlElement xmlParams)
Parameters
Type Name Description
IXmlElement xmlParams

The "init-params" IXmlElement to parse.

Returns
Type Description
object[]

An array of parameters.

Remarks

For the purpose of this method only the parameters that have the "param-type" element specified are processed. The following types are supported:

  • string (a.k.a. System.String)
  • bool (a.k.a. System.Boolean)
  • int (a.k.a. System.Int32)
  • long (a.k.a. System.Int64)
  • float (a.k.a. System.Single)
  • double (a.k.a. System.Double)
  • decimal (a.k.a. System.Decimal)
  • file (a.k.a. System.IO.File)
  • date (a.k.a. System.DateTime)
  • time (a.k.a. System.DateTime
  • xml (a.k.a. Tangosol.Run.Xml.IXmlElement)
For any other [explicitly specified] types the corresponding "init-param" IXmlElement itself is placed into the returned array.

ParseInitParams(IXmlElement, IParameterResolver)

Parse the specified "init-params" element of the following structure:

<!ELEMENT init-params (init-param*)>
<!ELEMENT init-param ((param-name | param-type), param-value,
description?)>

into an object array.

Declaration
public static object[] ParseInitParams(IXmlElement xmlParams, XmlHelper.IParameterResolver resolver)
Parameters
Type Name Description
IXmlElement xmlParams

The "init-params" IXmlElement to parse.

XmlHelper.IParameterResolver resolver

An XmlHelper.IParameterResolver to resolve "{macro}" values (optional).

Returns
Type Description
object[]

An array of parameters.

Remarks

For the purpose of this method only the parameters that have the "param-type" element specified are processed. The following types are supported:

  • string (a.k.a. System.String)
  • bool (a.k.a. System.Boolean)
  • int (a.k.a. System.Int32)
  • long (a.k.a. System.Int64)
  • double (a.k.a. System.Double)
  • float (a.k.a. System.Single)
  • decimal (a.k.a. System.Decimal)
  • file (a.k.a. System.IO.File)
  • date (a.k.a. System.DateTime)
  • time (a.k.a. System.DateTime
  • xml (a.k.a. Tangosol.Run.Xml.IXmlElement)
For any other [explicitly specified] types the corresponding "init-param" IXmlElement itself is placed into the returned array.

ParseMemorySize(string)

Parse the given string representation of a number of bytes.

Declaration
public static long ParseMemorySize(string s)
Parameters
Type Name Description
string s

A string with the format [\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[B|b]?

Returns
Type Description
long

The number of bytes represented by the given string.

Remarks

The supplied string must be in the format:

[\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[B|b]?

where the first non-digit (from left to right) indicates the factor with which the preceeding decimal value should be multiplied:

  • K or k (kilo, 210)
  • M or m (mega, 220)
  • G or g (giga, 230)
  • T or t (tera, 240)

If the string value does not contain a factor, a factor of one is assumed.

The optional last character B or b indicates a unit of bytes.

ParseMemorySize(string, int)

Parse the given string representation of a number of bytes.

Declaration
public static long ParseMemorySize(string s, int defaultPower)
Parameters
Type Name Description
string s

A string with the format [\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[B|b]?

int defaultPower

The exponent used to calculate the factor used in the conversion if one is not implied by the given string.

Returns
Type Description
long

The number of bytes represented by the given string.

Remarks

The supplied string must be in the format:

[\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[B|b]?

where the first non-digit (from left to right) indicates the factor with which the preceeding decimal value should be multiplied:

  • K or k (kilo, 210)
  • M or m (mega, 220)
  • G or g (giga, 230)
  • T or t (tera, 240)

If the string value does not contain an explict or implicit factor, a factor calculated by raising 2 to the given default power is used. The default power can be one of:

  • POWER_0
  • POWER_K
  • POWER_M
  • POWER_G
  • POWER_T

The optional last character B or b indicates a unit of bytes.

ParseTime(string)

Parse the given string representation of a time duration and return its value as a number of milliseconds.

Declaration
public static long ParseTime(string s)
Parameters
Type Name Description
string s

A string with the format [\d]+[[.][\d]+]?[MS|ms|S|s|M|m|H|h|D|d]?

Returns
Type Description
long

The number of milliseconds represented by the given string.

Remarks

The supplied string must be in the format:

[\d]+[[.][\d]+]?[MS|ms|S|s|M|m|H|h|D|d]?

where the first non-digits (from left to right) indicate the unit of time duration:

  • MS or ms (milliseconds)
  • S or s (seconds)
  • M or m (minutes)
  • H or h (hours)
  • D or d (days)

If the string value does not contain a unit, a unit of milliseconds is assumed.

ParseTime(string, int)

Parse the given string representation of a time duration and return its value as a number of milliseconds.

Declaration
public static long ParseTime(string s, int defaultUnit)
Parameters
Type Name Description
string s

A string with the format [\d]+[[.][\d]+]?[MS|ms|S|s|M|m|H|h|D|d]?

int defaultUnit

The unit to use in the conversion to milliseconds if one is not specified in the supplied string.

Returns
Type Description
long

The number of milliseconds represented by the given string.

Remarks

The supplied string must be in the format:

[\d]+[[.][\d]+]?[MS|ms|S|s|M|m|H|h|D|d]?

where the first non-digits (from left to right) indicate the unit of time duration:

  • MS or ms (milliseconds)
  • S or s (seconds)
  • M or m (minutes)
  • H or h (hours)
  • D or d (days)

If the string value does not contain a unit, the specified default unit is assumed. The default unit can be one of:

  • UNIT_MS
  • UNIT_S
  • UNIT_M
  • UNIT_H
  • UNIT_D

PurgeChildrenNamespace(IXmlElement)

For the children elements of the specified IXmlElement purge the repetetive Namespace declarations.

Declaration
public static void PurgeChildrenNamespace(IXmlElement xml)
Parameters
Type Name Description
IXmlElement xml

The IXmlElement.

PurgeNamespace(IXmlElement)

For the specified IXmlElement purge the Namespace declarations that are declared somewhere up the xml tree.

Declaration
public static void PurgeNamespace(IXmlElement xml)
Parameters
Type Name Description
IXmlElement xml

The IXmlElement.

Quote(string)

XML quote the passed string.

Declaration
public static string Quote(string s)
Parameters
Type Name Description
string s

The string to quote.

Returns
Type Description
string

The quoted string.

RemoveElement(IXmlElement, string)

Remove all immediate child elements with the given name.

Declaration
public static int RemoveElement(IXmlElement xml, string name)
Parameters
Type Name Description
IXmlElement xml

An IXmlElement.

string name

Child element name.

Returns
Type Description
int

The number of removed child elements.

Exceptions
Type Condition
InvalidOperationException

If the element is immutable or otherwise cannot remove a child element.

ReplaceElement(IXmlElement, IXmlElement)

Replace a child element with the same name as the specified element.

Declaration
public static bool ReplaceElement(IXmlElement xmlParent, IXmlElement xmlReplace)
Parameters
Type Name Description
IXmlElement xmlParent

Parent IXmlElement.

IXmlElement xmlReplace

Element to replace with.

Returns
Type Description
bool

true if matching child element has been found and replaced; false otherwise.

Remarks

If the child element does not exist the specified element is just added.

Exceptions
Type Condition
InvalidOperationException

If the parent element is immutable or otherwise cannot remove a child element.

TransformInitParams(IXmlElement, IXmlElement)

Transform the specified "init-params" element of the following structure:

<!ELEMENT init-params (init-param*)>
<!ELEMENT init-param ((param-name | param-type), param-value,
description?)>

into an XML element composed of the corrsponding names. For example, the "init-params" element of the following structure:

<init-param>
    <param-name>NameOne</param-name>
    <param-value>ValueOne</param-value>
</init-param>
<init-param>
    <param-name>NameTwo</param-name>
    <param-value>ValueTwo</param-value>
</init-param>

will transform into

<NameOne>ValueOne</NameOne>
<NameTwo>ValueTwo</NameTwo>
Declaration
public static void TransformInitParams(IXmlElement xmlParent, IXmlElement xmlParams)
Parameters
Type Name Description
IXmlElement xmlParent

The XML element to insert the transformed elements into.

IXmlElement xmlParams

The "init-params" IXmlElement to parse.

Remarks

For the purpose of this method only the parameters that have the "param-name" element specified are processed.

Trim(string)

Trim XML whitespace.

Declaration
public static string Trim(string s)
Parameters
Type Name Description
string s

The original string.

Returns
Type Description
string

The passed string minus any leading or trailing whitespace.

Remarks

See XML 1.0 2ed section 2.3.

Trimb(string)

Trim trailing XML whitespace.

Declaration
public static string Trimb(string s)
Parameters
Type Name Description
string s

The original string.

Returns
Type Description
string

The passed string minus any trailing whitespace.

Remarks

See XML 1.0 2ed section 2.3.

Trimf(string)

Trim leading XML whitespace.

Declaration
public static string Trimf(string s)
Parameters
Type Name Description
string s

The original string.

Returns
Type Description
string

The passed string minus any leading whitespace.

Remarks

See XML 1.0 2ed section 2.3.

In this article
Back to top Copyright © 2000, 2024, Oracle and/or its affiliates.