ASL
|
These functions allow parsing and writing data in XML, XDL and JSON formats.
Data can be decoded and encoded from/to a text string with:
The recommended way to load and parse a file is:
And the recommended way to encode and write data in these formats to a file is:
XDL, eXtensible Data Language, is a format for describing structured data as text. It has some similarities with the VRML syntax and with the JSON semantics.
The main differences with VRML syntax are that field name and value are separated with a '=', that boolean values are Y
nd N
and that array or property elements in the same line are separated with a ','. The main differences with JSON are that property names are not quoted, that objects can have a class name prepended, as in VRML, that elements can be separated with a newline instead of a comma, and that there can be C/C++ style comments. Whitespace and newlines can be removed to produce more compact representations.
Consider this XDL code:
That code represents an object of class Garage
with 3 properties: an integer capacity
, a boolean open
flag, a numeric array dimensions
and the vehicles
array. And that array contains two objects of different classes. If that fragment is stored in String garagex
it could be read like this:
We may construct a new Var or modify the one just parsed, and rewrite it as an XDL string.
The true
parameter makes the function write the code with new lines and indentations. By default the result is compact.
The JSON functions Json::encode()
, Json::decode()
do the same using JSON syntax. Class names are represented by a propery named $type
in this case (actually, the macro ASL_XDLCLASS). All of JSON syntax is supported.
Classes | |
struct | Json |
Functions to encode/decode data as JSON. More... | |
struct | Xdl |
Static functions to encode/decode XDL data. More... | |
class | Xml |
This class represents an XML element and can be used to manipulate a document DOM tree. More... | |