This object converts Zuble configuration files into JSON objects. More...
Import Statement: | import controller . |
The conversion algorithm is lossy beause the JSON format can't represent all possible XML object relationships and because text whitespace is compressed.
The advantage of using this object is you won't need to write XQuery code to retrieve XML file data. The limitation of using this object is your data MUST CONFORM to a set of rules listed below or else it can't be converted.
If your data doesn't conform you can either bring the data into conformance or write your own query to retrieve the data by using or extending the ZxQuery object.
The XML to JSON algorithm converts sequences of elements in XML files into arrays of JSON strings as follows:
XML elements with unique names within their parent scope are converted into properties of the same name within their parent JSON object, each containing either a string value or a JSON object. XML elements that have same-name siblings within their parent scope are converted into a JSON property of that name containing an array of strings or JSON objects.
XML elements that have no attributes and no child elements are converted to a JSON string property with a value equal to the XML element's concatenated, whitespace compressed text nodes.
XML elements with attributes or child elements are converted into JSON objects. XML attributes appear as a 'param' property containing a JSON object with a property name and string value for each XML attribute. XML text for such elements, if it exists after whitespace compression, appears in JSON as a 'value' property containing the element's concatenated text nodes (not including text of any child elements).
Doublequote characters in XML text are backslash-escaped.
XML conformity rules:
GOOD: <price_code> BAD: <price-code>
GOOD: <anything_else_JSON_conformant> BAD: <value> BAD: <param>
GOOD: <description>This text will not be changed.</description> BAD: <description> This text: whitespace will be trimmed and compressed, new lines and tabs will be lost and consecutive spaces will become a single space. </description>
GOOD: <item> <name>teeshirt</name> <care>machine wash warm</care> <size code="S"> <color>black</color> <color>gray</color> </size> <size code="M"/> <color>black</color> <color>gray</color> </size> <size code="L"/> <color>blue</color> <color weave="knit" lot="76">gray</color> </size> <item> BAD: <item> <name>teeshirt</name> <care>machine wash warm</care> <size code="S"/> <color>black</color> <color>gray</color> <size code="M"/> <color>black</color> <color>gray</color> <size code="L"/> <color>blue</color> <color weave="knit" lot="76">gray</color> <item>
EXAMPLE Javascript:
item.name === "teeshirt" item.care === "machine wash warm" item.size[0].param.code === "S" item.size[0].color[0] === "black" item.size[1].param.code === "M" item.size[2].color[0] === "blue" item.size[2].color[1].param.weave === "knit" item.size[2].color[1].param.lot === "76" item.size[2].color[1].value === "gray"
Zuble documentation copyright © 2019 Bob Dinitto. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Zuble is a derivative work of Qt version 5. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.