-
Notifications
You must be signed in to change notification settings - Fork 28
JavaScript Object Tree Format
4z3 edited this page May 21, 2012
·
1 revision
The JavaScript object tree format in an representation of XML data in JSON.
Suppose following XML document should be generated:
<?xml version="1.0" encoding="UTF-8"?>
<family name="Kawasaki">
<father>Yasuhisa</father>
<mother>Chizuko</mother>
<children>
<girl>Shiori</girl>
<boy>Yusuke</boy>
<boy>Kairi</boy>
</children>
</family>
Then the corresponding object tree would look like this:
{
"family": {
"-name": "Kawasaki",
"father": "Yasuhisa",
"mother": "Chizuko",
"children': {
"girl": "Shiori"
"boy': [
"Yusuke",
"Kairi"
]
}
}
};
Each elements are parsed into objects:
tree.family.father; // the father's given name.
Prefix '-' is inserted before every attributes' name.
tree.family["-name"]; // this family's family name
A array is used because this family has two boys.
tree.family.children.boy[0]; // first boy's name
tree.family.children.boy[1]; // second boy's name
tree.family.children.girl; // (girl has no other sisiters)