-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathebaParser.js
63 lines (58 loc) · 1.87 KB
/
ebaParser.js
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
// this file parses the EBA XML data using JS DOM manipulation
// Written by: Tony Le
(function() {
// var txt= "http://www.emmabandrews.org/eba_diary_content/eba_volume_19/volume-19_1912-1913.xml";
var file = "volume-19_1912-1913.xml";
var entireJSON; // variable for the entire converted JSON
// global variables go here
//
//
$(document).ready(function () {
callingXML();
createStructure();
});
function callingXML() {
var xmlDoc = loadXMLDoc(file);
var x2js = new X2JS();
entireJSON = x2js.xml2json(xmlDoc);
console.log(entireJSON);
//console.log("break");
}
function loadXMLDoc(fileName) {
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET", fileName, false);
xhttp.send();
return xhttp.responseXML;
}
// create function to go through each JSON line
// probably create individual objects and / or arrays for each "entry"
function createStructure() {
// loops over all 27 entries
entireJSON.TEI.text.body.div.forEach(function(entry) {
//console.log(entry);
// loops over date and paragraph of each 27
entry.p.forEach(function(dp) {
//console.log(dp);
var singleEntry = document.createElement("div");
$(singleEntry).attr("class", "allEntries");
var dateDiv = document.createElement("div");
var dateCurr = dp.title;
var nameCurr = dp.__text;
dateDiv.innerHTML = dateCurr;
dateDiv.style.textDecoration="underline";
singleEntry.innerHTML = nameCurr;
//console.log(dateCurr)
if (typeof(dateCurr) != "undefined") {
document.body.appendChild(dateDiv);
}
if (typeof(nameCurr) != "undefined") {
document.body.appendChild(singleEntry);
}
});
});
}
})();