Class
caplin.core

XmlUtility

Utility class that provides methods for manipulating and interacting with XML.

The #encodeValue and #decodeValue methods allow data that need to be stored and retrieved from XML to be encoded such that it doesn't contain illegal characters. The table below lists the characters that need to be encoded in this way.

Description Decoded Encoded
less than < &lt;
greater than > &gt;
ampersand & &amp;
apostrophe ' &apos;
quotation mark " &quot;

Constructor Summary

Attributes Name and Description
caplin.core.XmlUtility()

This is a static class that never needs to be instantiated.

Method Summary

Attributes Name and Description
<static> Map convertXmlNodeToAttributesMap(XmlNode oXmlNode, bStringBoolToBool)

Loops through all the attributes defined on the specified XML node and extracts them to a JavaScript map.

<static> void copyNodeAttributes(XmlNode oSourceXmlNode, XmlNode oTargetXmlNode)

Copy the attributes from the given source node, to the given target node.

<static> String decodeValue(Variant sValueToDecode)

Decodes the specified value and returns the result.

<static> String encodeValue(Variant vValueToEncode)

Encodes specified value and returns the result, such that it can be stored as a valid value in XML.

<static> boolean isValidAttributeName(String sAttributeName)

Determines whether the specified attribute name is valid or not.

<static> void selectSingleNode(XmlNode oNode, String sPath)

A cross-browser implementation of the XML Element method 'selectSingleNode'.

<static> String toJson(Object oXml, String sTab)

Converts a XML element into a JSON string.

Constructor Detail

caplin.core.XmlUtility()

This is a static class that never needs to be instantiated.

Method Detail

<static> Map convertXmlNodeToAttributesMap(XmlNode oXmlNode, bStringBoolToBool)

Loops through all the attributes defined on the specified XML node and extracts them to a JavaScript map. Only the attributes on the specified XML node will be inserted into the map - any attributes on child nodes will be ignored.

Each of the values that are retrieved from the XML node's attribute have been decoded.

Parameters
XmlNode oXmlNode The XML node to be converted.
bStringBoolToBool
Returns
A map of name/value pairs for all the attributes defined in the specified XML node.

<static> void copyNodeAttributes(XmlNode oSourceXmlNode, XmlNode oTargetXmlNode)

Copy the attributes from the given source node, to the given target node.

Parameters
XmlNode oSourceXmlNode the node from which the attributes will be copied from.
XmlNode oTargetXmlNode the node to which the attributes will be copied to.

<static> String decodeValue(Variant sValueToDecode)

Decodes the specified value and returns the result. This method reverts the encoding performed by the #encodeValue method, although it will only ever return a string. For example, if a number were encoded, then a string representing that number will be decoded.

This method requires the specified value to have a valid encoding, if it doesn't then an exception will be thrown. For example, FX &amp FI is invalid as the encoding is missing a semicolon. Please see caplin.core.XmlUtility for more information on which characters are encoded.

Parameters
Variant sValueToDecode The value to be decoded. This may not be null or undefined, and it must be a valid encoding.
Throws
caplin.core.Error
if the specified value to encode is null or undefined, or if it is not one of the valid character encodings.
Returns
The encoded value.

<static> String encodeValue(Variant vValueToEncode)

Encodes specified value and returns the result, such that it can be stored as a valid value in XML. Non-Strings can be encoded, however they are converted to strings.

The #decodeValue method will convert the encoded value back.

Please see caplin.core.XmlUtility for more information on which characters are encoded.

Parameters
Variant vValueToEncode The value to be encoded. This may not be null or undefined, and all values will be converted to Strings.
Throws
caplin.core.Error
if the specified value to encode is null or undefined.
Returns
The encoded value.

<static> boolean isValidAttributeName(String sAttributeName)

Determines whether the specified attribute name is valid or not.

An attribute name is valid if it begins with a letter (upper or lower case) or an underscore, and is followed by any number of letters, numbers, underscores or minus signs. Expressed as a regular expression, this rule is: ^[A-Za-z_][A-Za-z0-9_-]*

Parameters
String sAttributeName The name of the attribute to be tested.
Returns
true if the specified name is valid, otherwise false.

<static> void selectSingleNode(XmlNode oNode, String sPath)

A cross-browser implementation of the XML Element method 'selectSingleNode'.

Parameters
XmlNode oNode The root XML node.
String sPath The XPath expression to evaluate.
Returns
The first node that matches the XPath expression.

<static> String toJson(Object oXml, String sTab)

Converts a XML element into a JSON string. Useful for serializing JSON configurations in your layout. See caplin.core.JsonUtility.toXml for how to convert JSON back to XML.

Parameters
Object oXml The XML object that will be converted.
String sTab Tab delimiter to use (defaults to an empty string)
Returns
{String} A JSON string.