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 | < | < |
greater than | > | > |
ampersand | & | & |
apostrophe | ' | ' |
quotation mark | " | " |
Attributes | Name and Description |
---|---|
|
caplin.core.XmlUtility()
This is a static class that never needs to be instantiated. |
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. |
►
caplin.core.XmlUtility()
This is a static class that never needs to be instantiated.
►
<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.
XmlNode | oXmlNode | The XML node to be converted. |
bStringBoolToBool |
►
<static>
void
copyNodeAttributes(XmlNode oSourceXmlNode, XmlNode oTargetXmlNode)
Copy the attributes from the given source node, to the given target node.
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 & FI
is invalid as the encoding is
missing a semicolon. Please see caplin.core.XmlUtility for more information on which
characters are encoded.
Variant | sValueToDecode | The value to be decoded. This may not be null or
undefined , and it must be a valid encoding. |
null
or
undefined
, or if it is not one of the valid character encodings.
►
<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-String
s 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.
Variant | vValueToEncode | The value to be encoded. This may not be null or
undefined , and all values will be converted to Strings. |
null
or
undefined
.
►
<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_-]*
String | sAttributeName | The name of the attribute to be tested. |
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'.
XmlNode | oNode | The root XML node. |
String | sPath | The XPath expression to evaluate. |
►
<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.
Object | oXml | The XML object that will be converted. |
String | sTab | Tab delimiter to use (defaults to an empty string) |