-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxml2jsonp.html
56 lines (52 loc) · 2.47 KB
/
xml2jsonp.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
/*
This file is part of the HBP Neuron Morphology Viewer.
HBP Neuron Morphology Miner is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
HBP Neuron Morphology Viewer is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with HBP morphology viewer.
If not, see <http://www.gnu.org/licenses/>
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>XML to JSON or JSONP converter</title>
<script type="text/javascript" src="./js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="./js/morphology_parser.js"></script>
<script type="text/javascript" src="./js/FileSaver.min.js"></script>
<script type="text/javascript">
function convert(elem) {
var xmlString = $('#xmlString').val()
var parser = new DOMParser();
try {
var xmlDoc = parser.parseFromString(xmlString,'text/xml')
var errors = xmlDoc.getElementsByTagName('parsererror')
if (errors.length) throw('XML parser error: '+errors[0].innerHTML)
var xmlTest = (new XMLSerializer()).serializeToString(xmlDoc.documentElement)
var data = xmlLib.toDict([xmlDoc.documentElement])
jsonpString = 'callback('+JSON.stringify(data,null,2)+')';
} catch(e) {
jsonpString = 'Cannot parse XML: '+e
}
$('#jsonpString').val(jsonpString)
}
</script>
<style type="text/css">
body { font-family:Gotham,Arial,sans-serif;font-size:12px;line-height:1.3;color:rgb(0,0,0);background-color: #f8f8f8 }
textarea { width: 96%; margin:0.2%; height:20em }
</style>
</head>
<body onload="">
<div>Paste XML here:<br/><textarea id="xmlString"></textarea><br/><input type="button" onclick="convert(this)" value="Convert XML to JSONP"/></div>
<br/>
<div>Conversion result:<br/><textarea id="jsonpString"></textarea></div>
</body>
</html>