forked from NaturalIntelligence/fast-xml-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
199 lines (181 loc) · 9.87 KB
/
index.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE html>
<html lang="en">
<head>
<title>Fast XMl Parser</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="static/css/font-awesome.min.css">
<link rel="stylesheet" href="static/css/bootstrap.min.css">
<link rel="stylesheet" href="static/css/prettify.min.css">
<link rel="stylesheet" href="static/css/jquery-confirm.min.css">
<script src="static/js/jquery-3.2.1.min.js"></script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/prettify.min.js"></script>
<link rel="stylesheet" type="text/css" href="static/css/animate3.5.2.min.css">
<script src="lib/parser.js"></script>
<script src="static/js/jquery-confirm.min.js"></script>
</head>
<body>
<body role="document" style="background-color: #2c3e50;">
<div class="container-fluid">
<a href="https://github.com/NaturalIntelligence/fast-xml-parser"><img class="bring-up" style="position: absolute; top: 0; left: 0; border: 0; z-index: 1" src="https://camo.githubusercontent.com/121cd7cbdc3e4855075ea8b558508b91ac463ac2/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f6c6566745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_left_green_007200.png"></a>
<h1 style="color:white;" class="text-center">Fast XML Parser</h1>
<p></p>>
<div class="row" style="height: calc(100vh - 100px);">
<div class="col-md-4" >
<span class="float-right" style="color: white"> <span id="lengthxml" style="margin:5px">0</span> bytes</span>
<textarea id="txtXml" name="xml" style="width: 100%; height: 100%" class="form-control" placeholder="Paste XML to parse in JS/JSON"></textarea>
</div>
<div class="col-md-4" style=" color: white;">
<div style="border: 1px dashed grey; margin: 5px; padding: 5px;">
<input type="checkbox" id="attrNodeName"> Group all the attributes <br>
<input type="checkbox" id="ignoreAttributes" checked="true"> Ignore attributes <br>
<input type="checkbox" id="ignoreNameSpace"> Remove namespace string from tag and attribute names. <br>
<input type="checkbox" id="parseNodeValue" checked="true"> Parse text-node's value to float / integer / boolean.<br>
<input type="checkbox" id="ParseAttributeValue"> Parse attribute's value to float / integer / boolean.<br>
<input type ="checkbox" id="allowBooleanAttributes"> Allow Boolean Attributes <br>
<input type ="checkbox" id="trimValues" checked="true" > Trim<br>
<span class="clearfix">TagName to parse CDATA as separate property <input type="text" id="cdataTagName" style=" color: black; float:right;" ><br></span>
<span class="clearfix">Locale range <input type="text" id="localeRange" style=" color: black; float:right;" placeholder="Try with your mother tongue"><br></span>
<div class="text-center" style="margin: 15px">
<button id="toJson" class="btn btn-primary" type="button">Parse to JSON >> </button>
<button id="toNimn" class="btn btn-primary" type="button">Parse to Nimn >> </button>
</div>
</div>
<div style="border: 1px dashed grey; margin: 5px; padding: 5px;">
<input type="checkbox" id="allowBooleanAttributes_v"> Allow Boolean Attributes<br>
<span class="clearfix">Locale range <input type="text" id="localeRange_v" style=" color: black; float:right;" placeholder="Try with your mother tongue"><br></span>
<div class="text-center" style="margin: 15px">
<button id="validate" class="btn btn-primary" type="button">Validate XML >> </button>
</div>
</div>
</div>
<div class="col-md-4">
<span class="float-right" style="color: white"><span id="lengthoutput" style="margin:5px">0</span> bytes</span>
<textarea id="result" style="width: 100%; height: 100%" class="form-control" placeholder="Output"></textarea>
</div>
</div>
</div>
<script src="https://cdn.rawgit.com/nimndata/nimnjs-schema-builder/5a452c40/dist/nimn-schema-builder.js"></script>
<script>
$( document ).ready(function() {
//var parser = require("parser");
$('#txtXml').on('input', function(){
updateLength();
});
$('#toJson').on('click', function() {
$('#result').empty();
var result = parser.parse($('#txtXml').val(),buildParsingConfig());
updateOutputLength(JSON.stringify(result));
$('#result').text(JSON.stringify(result,null,4));
});
$('#toNimn').on('click', function() {
$('#result').empty();
var jsonData = parser.parse($('#txtXml').val(),buildParsingConfig());
var schema = nimnSchemaBuilder.build(jsonData);
var result = parser.parseToNimn($('#txtXml').val(), schema, buildParsingConfig());
updateOutputLength(result);
$('#result').text(result);
});
$('#validate').on('click', function() {
$('#result').empty();
var config = {
allowBooleanAttributes: $("#allowBooleanAttributes_v").prop("checked"),
localeRange : $("#localeRange_v").val() === "" ? "a-zA-Z" : $("#cdataTagName").val(),
};
var val = parser.validate($('#txtXml').val(), config);
if(val === true){
$('#result').text("Valid XML");
}else{
$('#result').text(JSON.stringify(val,null,4));
}
});
optionsLogic();
$('#ignoreAttributes').on('change', function (){optionsLogic();});
function buildParsingConfig(){
var config = {
attributeNamePrefix : "",
attrNodeName: $("#attrNodeName").prop("checked") ? "@" : false,
textNodeName : "#text",
ignoreAttributes : $("#ignoreAttributes").prop("checked"),
ignoreNameSpace : $("#ignoreNameSpace").prop("checked"),
parseNodeValue : $("#parseNodeValue").prop("checked"),
parseAttributeValue : $("#parseAttributeValue").prop("checked"),
allowBooleanAttributes: $("#allowBooleanAttributes").prop("checked"),
trimValues: $('#trimValues').prop("checked"), //Trim string values of tag and attributes
decodeHTMLchar: false,
cdataTagName: $("#cdataTagName").val() === "" ? false : $("#cdataTagName").val(),
cdataPositionChar: "\\c",
localeRange : $("#localeRange_v").val(),
//arrayMode : $("#arrayMode").prop("checked")
};
return config;
}
function optionsLogic(){
var ignoreAttr = $('#ignoreAttributes').prop('checked');
if(ignoreAttr){
$('#attrNodeName').prop('checked', !ignoreAttr);
$('#ParseAttributeValue').prop('checked', !ignoreAttr);
$('#allowBooleanAttributes').prop('checked', !ignoreAttr);
}
$('#attrNodeName').attr('disabled', ignoreAttr);
$('#ParseAttributeValue').attr('disabled', ignoreAttr);
$('#allowBooleanAttributes').attr('disabled', ignoreAttr);
return;
}
function updateLength(){
var xmlData = $('#txtXml').val();
$("#lengthxml")[0].innerText = xmlData.replace(/>\s*</g, "><").length;
}
function updateOutputLength(data){
$("#lengthoutput")[0].innerText = data.length;
}
$('#txtXml').text(`
<?xml version="1.0"?>
<any_name>
<person>
<phone>+122233344550</phone>
<name>Jack</name>
<phone>+122233344551</phone>
<age>33</age>
<married firstTime="No">Yes</married>
<birthday>Wed, 28 Mar 1979 12:13:14 +0300</birthday>
<address>
<city>New York</city>
<street>Park Ave</street>
<buildingNo>1</buildingNo>
<flatNo>1</flatNo>
</address>
<address>
<city>Boston</city>
<street>Centre St</street>
<buildingNo>33</buildingNo>
<flatNo>24</flatNo>
</address>
</person>
<person>
<phone>+122233344553</phone>
<name>Boris</name>
<phone>+122233344554</phone>
<age>34</age>
<married firstTime="Yes">Yes</married>
<birthday>Mon, 31 Aug 1970 02:03:04 +0300</birthday>
<address>
<city>Moscow</city>
<street>Kahovka</street>
<buildingNo>1</buildingNo>
<flatNo>2</flatNo>
</address>
<address>
<city>Tula</city>
<street>Lenina</street>
<buildingNo>3</buildingNo>
<flatNo>78</flatNo>
</address>
</person>
</any_name>`);
updateLength();
});
</script>
</body>
</html>