This repository was archived by the owner on Feb 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonixexample.html
More file actions
65 lines (61 loc) · 3.31 KB
/
jsonixexample.html
File metadata and controls
65 lines (61 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jsonix example</title>
<script type="text/javascript" src="jsonix/jsonix-scripts-1.0-all.js"></script>
<script type="text/javascript" src="biz/leverenz/clsimplexsd/Mappings.js"></script>
<script type="text/javascript">
// create some namespaces
if (typeof (biz) === 'undefined') {
biz = {};
}
if (typeof (biz.leverenz) === 'undefined') {
biz.leverenz = {};
}
if (typeof (biz.leverenz.jsonixexample) === 'undefined') {
biz.leverenz.jsonixexample = {};
}
if (typeof (biz.leverenz.jsonixexample.functions) === 'undefined') {
biz.leverenz.jsonixexample.functions = {};
}
if (typeof (biz.leverenz.jsonixexample.data) === 'undefined') {
biz.leverenz.jsonixexample.data = {};
}
// the central getcontext method of jsonix
biz.leverenz.jsonixexample.functions.getContext = function () {
if (typeof (biz.leverenz.jsonixexample.data.jsonixcontext) == 'undefined') {
biz.leverenz.jsonixexample.data.jsonixcontext = new Jsonix.Context([biz.leverenz.clsimplexsd.Mappings]);
}
return biz.leverenz.jsonixexample.data.jsonixcontext;
}
// create an unmarshaller for our xml data (single use only...)
biz.leverenz.jsonixexample.functions.getUnmarshaller = function () {
return biz.leverenz.jsonixexample.functions.getContext().createUnmarshaller();
}
// get the xml data and unmarshal it
biz.leverenz.jsonixexample.functions.init = function () {
// the unmarshalurl method accpets an urls and a function which is called in case of success
biz.leverenz.jsonixexample.functions.getUnmarshaller().unmarshalURL("clsimple.xml",
function (data) { // call, when the xml could be unmarshaled from the data specified by the url
if (data.value) { // vthe node value will contain the true data
biz.leverenz.jsonixexample.data.xmldata = data.value; // just remember the data...
var targetelement = document.getElementById("mydata"); // some debugoutput from the read data
for (var i = 0 ; i < data.value.anentry.length ; i++) { // anentry occours as an array due to the xsd definition
var theentry = data.value.anentry[i];
var thenumber = theentry.anumber; // the subnode anumber becomes directly a member of anentry, because it has no attributes
var thename = theentry.name; // the attribute name of anentry becomes also a member of this entry
var thestring = theentry.astring; // the subnode astring
var anewchild = document.createElement("div"); // ok, just display them in asimple div for demo
anewchild.innerText = thename + " - " + thenumber + " - " + thestring;
targetelement.appendChild(anewchild);
}
}
});
}
</script>
</head>
<body>
<button onclick="biz.leverenz.jsonixexample.functions.init()">load xml</button>
<div id="mydata"></div>
</body>
</html>