-
Notifications
You must be signed in to change notification settings - Fork 1
/
example2.html
158 lines (144 loc) · 6.46 KB
/
example2.html
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<h1>Example 2 : Parsing VOTable</h1>
URL of VOTable to parse: <input type="text" name="votable" size="100" id="votableUrl" value="https://ssp.imcce.fr/webservices/miriade/api/rts.php?-observer=0%200%200.0&-ep=2458521.5&-nbd=1&-body=11,10&-fmt=twilight:0,timerep:decimal,time:second,coordrep:decimal,coord:arcsec,az:North&-lang=fr&-from=sspdev&-extrap=8">
<a class="button" href="#">
<img src="http://findicons.com/files/icons/109/play_stop_pause/128/play1disabled.png" alt="sublit" height="20"
width="20" />Submit
</a>
<br /><br />
<div id="myWidget"></div>
<script type="text/javascript" src="../JsVotable.min.js"></script>
<script type="text/javascript" src="../node_modules/jquery/dist/jquery.min.js"></script>
<script type="text/javascript">
var VotableWidget = (function () {
var self = {};
function parseVotable(xhr, output) {
var outputGroup = "";
var votable = new JsVotable.Votable(xhr.responseXML);
var groups = votable.getGroups();
for (i = 0; i < groups.length; i++) {
var group = groups[i];
outputGroup += "<fieldset><legend>" + group.utype() + "</legend>";
var subGroups = group.getGroups();
for (j = 0; j < subGroups.length; j++) {
var subGroup = subGroups[j];
outputGroup += "<fieldset><legend>" + subGroup.utype() + "</legend>";
var params = subGroup.getParams();
for (k = 0; k < params.length; k++) {
var param = params[k];
outputGroup += param.name() + " : " + param.value() + "<br/>";
}
outputGroup += "</fieldset>";
}
outputGroup += "</fieldset>";
}
var infos = votable.getInfos();
if(infos != null) {
for (var indexInfo=0 ; indexInfo < infos.length ; indexInfo++) {
var info = infos[indexInfo];
var name = info.name();
var value = info.value();
output = output + "INFO "+name+" = "+value;
var txt = info.getContent();
if(txt != null) {
output = output + ":" + txt;
}
output = output + "<br/>";
}
}
output = output+"<br/>";
var resource = votable.getResources()[0];
var description = resource.getDescription();
if (description!=null) {
output = output+description.getContent()+"<br/><br/>"
}
var resourcesOrTables = resource.getResourcesOrTables();
for (elt = 0; elt < resourcesOrTables.length; elt++) {
var resourceOrTable = resourcesOrTables[elt];
if (resourceOrTable.getTagName() != JsVotable.Constants.TAG.TABLE) {
// do nothing
} else {
var table = resourceOrTable;
var fields = table.getFields();
var data = table.getData();
if (data != null && data.getDataImplementationName() == JsVotable.Constants.TAG.TABLEDATA) {
var id = table.ID();
if( id != null ) {
output += id + "<br>";
}
output += "<table border='1'>";
var tabledata = data.getData();
var trs = tabledata.getTrs();
output += "<tr>";
for (i = 0; i < fields.length; i++) {
var field = fields[i];
output += "<th>" + field.name() + "</th>";
}
output += "</tr>";
for (i = 0; i < trs.length; i++) {
output += "<tr>";
var tr = trs[i];
var tds = tr.getTds();
for (j = 0; j < tds.length; j++) {
var td = tds[j];
output += "<td>" + td.getContent() + "</td>";
}
output += "</tr>";
}
output += "</table><br/>";
} else {
for (i = 0; i < fields.length; i++) {
var field = fields[i];
output += "<b>" + field.name() + "</b> : " + field.ucd() + "</br>";
}
}
}
}
return outputGroup + output;
}
self.do_work = function (div) {
var xhr = new XMLHttpRequest();
xhr.open('GET', document.getElementById("votableUrl").value, false);
xhr.send(null);
var output = "";
if (xhr.status == 200) {
try {
output += parseVotable(xhr, output);
} catch (e) {
output += "Error : " + e;
}
} else {
output += "Error when retrieving the VOTable, Please change the URL";
}
document.getElementById(div).innerHTML = output;
};
return self;
})();
$('.button').on('click', function (e) {
VotableWidget.do_work('myWidget');
e.preventDefault();
});
</script>
</body>
</html>