Many API recieve/send data in form of XML or JSON or both. And there is a problem of transformation between XML and JSON. This isn't simple problem because underline data models are incompatible: XML bases on trees, JSON bases on arrays and dictionaries.
There are many possible solutions to this problem.
AXON allows to make transformation to/from XML or JSON easier. That's because underline data model of AXON supports trees, arrays and dictionaries. Let's consider examples.
JSON:
{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}
XML:
<menu id="file" value="File">
<popup>
<menuitem value="New" onclick="CreateNewDoc()" />
<menuitem value="Open" onclick="OpenDoc()" />
<menuitem value="Close" onclick="CloseDoc()" />
</popup>
</menu>
This example explain two styles of representation:
AXON can represent this example using both forms of representation:
JSON style:
{menu: {
id: "file"
value: "File"
popup: {
menuitem: [
{value: "New" onclick: "CreateNewDoc()"}
{value: "Open" onclick: "OpenDoc()"}
{value: "Close" onclick: "CloseDoc()"}
]
}
}}
XML style:
menu {
id: "file"
value: "File"
popup {
menuitem { value: "New" onclick: "CreateNewDoc()" }
menuitem { value: "Open" onclick: "OpenDoc()" }
menuitem { value: "Close" onclick: "CloseDoc()" }
}
}
One could use also mixed style of representation:
menu {
id: "file"
value: "File"
popup {
menuitems {
{value: "New" onclick: "CreateNewDoc()"}
{value: "Open" onclick: "OpenDoc()"}
{value: "Close" onclick: "CloseDoc()"}
}
}
}
<menu
id: "file"
value: "File"
<popup
<menuitems
{value: "New" onclick: "CreateNewDoc()"}
{value: "Open" onclick: "OpenDoc()"}
{value: "Close" onclick: "CloseDoc()"}
>
>
>
JSON:
{"widget": {
"debug": "on",
"window": {
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}}
XML:
<widget>
<debug>on</debug>
<window title="Sample Konfabulator Widget">
<name>main_window</name>
<width>500</width>
<height>500</height>
</window>
<image src="Images/Sun.png" name="sun1">
<hOffset>250</hOffset>
<vOffset>250</vOffset>
<alignment>center</alignment>
</image>
<text data="Click Here" size="36" style="bold">
<name>text1</name>
<hOffset>250</hOffset>
<vOffset>100</vOffset>
<alignment>center</alignment>
<onMouseUp>
sun1.opacity = (sun1.opacity / 100) * 90;
</onMouseUp>
</text>
</widget>
Here reprsentation using AXON.
XML style:
widget {
debug: "on"
window {
title: "Sample Konfabulator Widget"
name {"main_window"}
width {500}
height {500}}
image {
src: "Images/Sun.png"
name: "sun1"
hOffset {250}
vOffset {250}
alignment {"center"}}
text {
data: "Click Here"
size: 36
style: "bold"
name {"text1"}
hOffset {250}
vOffset {100}
alignment {"center"}
onMouseUp {"sun1.opacity = (sun1.opacity / 100) * 90;"}}}
JSON style:
widget: {
debug: "on"
window: {
title: "Sample Konfabulator Widget"
name: "main_window"
width: 500
height: 500
}
image: {
src: "Images/Sun.png"
name: "sun1"
hOffset: 250
vOffset: 250
alignment: "center"
}
text: {
data: "Click Here"
size: 36
style: "bold"
name: "text1"
hOffset: 250
vOffset: 100
alignment: "center"
onMouseUp: "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}}
Mixed style:
widget {
debug: "on"
window {
title: "Sample Konfabulator Widget"
name: "main_window"
width: 500
height: 500}
image {
src: "Images/Sun.png"
name: "sun1"
hOffset: 250
vOffset: 250
alignment: "center"}
text {
data: "Click Here"
size: 36
style: "bold"
name: "text1"
hOffset: 250
vOffset: 100
alignment: "center"
onMouseUp: "sun1.opacity = (sun1.opacity / 100) * 90;"}
}
JSON:
{"menu": {
"header": "SVG Viewer",
"items": [
{"id": "Open"},
{"id": "OpenNew", "label": "Open New"},
null,
{"id": "ZoomIn", "label": "Zoom In"},
{"id": "ZoomOut", "label": "Zoom Out"},
{"id": "OriginalView", "label": "Original View"},
null,
{"id": "Quality"},
{"id": "Pause"},
{"id": "Mute"},
null,
{"id": "Find", "label": "Find..."},
{"id": "FindAgain", "label": "Find Again"},
{"id": "Copy"},
{"id": "CopyAgain", "label": "Copy Again"},
{"id": "CopySVG", "label": "Copy SVG"},
{"id": "ViewSVG", "label": "View SVG"},
{"id": "ViewSource", "label": "View Source"},
{"id": "SaveAs", "label": "Save As"},
null,
{"id": "Help"},
{"id": "About", "label": "About Adobe CVG Viewer..."}
]
}}
XML:
<menu>
<header>Adobe SVG Viewer</header>
<item action="Open" id="Open">Open</item>
<item action="OpenNew" id="OpenNew">Open New</item>
<separator/>
<item action="ZoomIn" id="ZoomIn">Zoom In</item>
<item action="ZoomOut" id="ZoomOut">Zoom Out</item>
<item action="OriginalView" id="OriginalView">Original View</item>
<separator/>
<item action="Quality" id="Quality">Quality</item>
<item action="Pause" id="Pause">Pause</item>
<item action="Mute" id="Mute">Mute</item>
<separator/>
<item action="Find" id="Find">Find...</item>
<item action="FindAgain" id="FindAgain">Find Again</item>
<item action="Copy" id="Copy">Copy</item>
<item action="CopyAgain" id="CopyAgain">Copy Again</item>
<item action="CopySVG" id="CopySVG">Copy SVG</item>
<item action="ViewSVG" id="ViewSVG">View SVG</item>
<item action="ViewSource" id="ViewSource">View Source</item>
<item action="SaveAs" id="SaveAs">Save As</item>
<separator/>
<item action="Help" id="Help">Help</item>
<item action="About" id="About">About Adobe CVG Viewer...</item>
</menu>
AXON:
menu {
header: "SVG Viewer"
items {
{id: "Open"}
{id: "OpenNew" label: "Open New"}
null
{id: "ZoomIn" label: "Zoom In"}
{id: "ZoomOut" label: "Zoom Out"}
{id: "OriginalView" label: "Original View"}
null
{id: "Quality"}
{id: "Pause"}
{id: "Mute"}
null
{id: "Find" label: "Find..."}
{id: "FindAgain" label: "Find Again"}
{id: "Copy"}
{id: "CopyAgain" label: "Copy Again"}
{id: "CopySVG", label: "Copy SVG"}
{id: "ViewSVG", label: "View SVG"}
{id: "ViewSource" label: "View Source"}
{id: "SaveAs" label: "Save As"}
null
{id: "Help"}
{id: "About" label: "About Adobe CVG Viewer..."}
}
}
JSON:
{"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}}
XML:
<!DOCTYPE glossary PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
<glossary><title>example glossary</title>
<GlossDiv><title>S</title>
<GlossList>
<GlossEntry ID="SGML" SortAs="SGML">
<GlossTerm>Standard Generalized Markup Language</GlossTerm>
<Acronym>SGML</Acronym>
<Abbrev>ISO 8879:1986</Abbrev>
<GlossDef>
<para>A meta-markup language, used to create markup
languages such as DocBook.</para>
<GlossSeeAlso OtherTerm="GML">
<GlossSeeAlso OtherTerm="XML">
</GlossDef>
<GlossSee OtherTerm="markup">
</GlossEntry>
</GlossList>
</GlossDiv>
</glossary>
AXON:
glossary {
title: "example glossary"
GlossDiv {
title: "S"
GlossList {
GlossEntry {
ID: "SGML"
SortAs: "SGML"
GlossTerm: "Standard Generalized Markup Language"
Acronym: "SGML"
Abbrev: "ISO 8879:1986"
GlossSee: "markup"
GlossDef: {
para: "A meta-markup language, used to create markup
languages such as DocBook."
GlossSeeAlso: ["GML" "XML"]
}
}
}
}
}
In [ ]: