API Reference
Still have questions?
Contact support
You are looking at an outdated 7.6.0 version of this document. Switch to the 8.1.0 version to see the up to date information.

namespace anychart.utils Improve this Doc

Functions Overview

defaultDateFormatter()Formats incoming timestamp as 'yyyy.MM.dd'.
json2xml()Converts JSON object to an XML Node tree or String (string by default).
xml2json()Public function that parses XML and returns JSON. It hides all errors in

Functions Description


Formats incoming timestamp as 'yyyy.MM.dd'.


Name Type Description
timestamp number | string Timestamp.


string - - Formatted date.


Converts JSON object to an XML Node tree or String (string by default).


Name Type Description
json Object | string
rootNodeName string
returnAsXmlNode boolean


string Node -


Public function that parses XML and returns JSON. It hides all errors in Document structure, so the result may be not as strict as expected. The function converts XML string or node to an object with attributes introduced as same named string properties. All subnodes are also converted to correspondingly named properties by the next rules: - if there is only one child with this name, it is converted into an object an added just as an object property to the parent object. - if there are multiple children with the same name, they are also converted to a separate objects and then added to the parent object as an array. - if there is an attribute named just like the node(s), the node(s) will completely replace the attribute. - if there is any text value or a CDATA node or any their combination in the node, that value is stored as a string in a property named "value" even in cases when there is a subnode named "value" (but the node with this name still can be found in "#children#" array mentioned below). Also some service properties are added to an object representing a node: - "#name#" property - the node name - "#children#" array property - all node children listed in order they appear in the node - mentioned above "value" string property - contains textual value of the node Usage sample: var a = new XMLHttpRequest();'GET', '', false, "", ""); a.send(null); // for example there was the next XML: // // // some text value // // var json = anychart.utils.XML2JSON(a.responseXML); json variable will have the following structure: { #name#: "root", #children#: [ {#name#: "child", #children#: []}, {#name#: "child", #children#: [], value: "some text value and a CDATA "} {#name#: "child_other", #children#: []} ], a: "123", child: [ {#name#: "child", #children#: []}, {#name#: "child", #children#: [], value: "some text value and a CDATA "} ], child_other: {#name#: "child_other", #children#: []} }


Name Type Description
xml string | Node XML source string.


Object string - Transformation result JSON (may by null).