Skip to content

Latest commit

 

History

History
89 lines (85 loc) · 3.39 KB

utils.adoc

File metadata and controls

89 lines (85 loc) · 3.39 KB

/** * The anychart.utils namespace contains static utility methods. * @namespace * @name anychart.utils */ anychart.utils;

/** * 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 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: * <pre> * var a = new XMLHttpRequest(); * a.open('GET', 'https://sample.com', false, '', ''); * a.send(null); * // for example there was the next XML: * // <root a='123'> * // <child /> * // <child>some text value<![CDATA[ and a CDATA ]]></child> * // <child_other/> * // </root> * var json = anychart.utils.XML2JSON(a.responseXML); * </pre> * 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: []} * } * @category XML/JSON * @param {string|Node} xml XML source string. * @return {Object|string} Transformation result JSON (may by null). */ anychart.utils.xml2json;

/** * Converts JSON object to an XML Node tree or String (string by default). * @category XML/JSON * @param {Object|string} json JSON source object or string. * @param {string=} opt_rootNodeName Root node name. * @param {boolean=} opt_returnAsXmlNode Whether to return value as XML node. * @return {string|Node} */ anychart.utils.json2xml;

/** * Hide all tooltips. * @category Specific settings * @param {boolean=} opt_force Ignore tooltips hide delay. */ anychart.utils.hideTooltips;

/** * Creates HTML Table from CSV string. * @param {string} csv CSV string. * @param {string=} opt_title Title to set. * @param {boolean=} opt_asString Defines output: HTML string if True, DOM element if False. * @param {Object=} opt_csvSettings CSV settings. * @return {?Element} HTML table instance, HTML string or null if parsing CSV to table fails. */ anychart.utils.htmlTableFromCsv;