-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvalidate.html
60 lines (56 loc) · 2.01 KB
/
validate.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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<script
src="https://code.jquery.com/jquery-3.7.1.js"
integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4="
crossorigin="anonymous"></script>
<script type="text/javascript" src="node_modules/xmlschema.js/dist/xmlschema.js"></script>
</head>
<body>
<div class="col-xs-12" style="text-align: center">
<h1>X3D XML validate</h1>
<button id="validate">Validate</button>
<div><a href="validate.html">validate X3D XML demo</a></div>
</div>
<div class="col-xs-6 col-xs-offset-1"><textarea style="width: 100%; height: 500px" id="xml"></textarea></div>
<div class="col-xs-4"><textarea style="width: 100%; height: 500px" id="xsd"></textarea></div>
<div class="col-xs-10 col-xs-offset-1" style="text-align: center">
<textarea style="width: 100%; height: 300px" id="log"></textarea>
</div>
<script type="text/javascript">
var xsdjs = xmlschema(['https://localhost:3000/src/specifications/x3d-4.0.xsd']);
function validate(xml, callback) {
xsdjs.validate(xml).then(function(result) {
if (result.valid) {
alert("It worked!");
$("#log").text(result.message);
} else {
var output = "";
result.errors.forEach(function (error) {
output += "ERROR: " + error + "\n";
});
result.warnings.forEach(function (warn) {
output += "WARNING: " + warn + "\n";
});
$("#log").text(output);
}
if (callback) {
callback(result);
}
}).catch(function (message) {
$("#log").text(message);
});
}
$("#validate").click(function () {
$("#log").text("");
validate($("#xml").val());
});
validate('src/main/data/abox.x3d', function (result) {
$("#xml").text(result.xml.str);
$("#xsd").text(result.xsd.str);
})
</script>
</body>
</html>