-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathxml.htm
More file actions
223 lines (210 loc) · 9.04 KB
/
Copy pathxml.htm
File metadata and controls
223 lines (210 loc) · 9.04 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<link REL="SHORTCUT ICON" HREF="img/shanti.ico">
<title>VisualEyes</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>
Hello
<script>
$.ajax({
url: 'SAD.xml', dataType: 'xml',
success: function(data) { parseXML(data) },
error: function(data) { console.log('Error loading XML data'); }
});
function parseXML(xml) {
var x,a;
var s=MakeLine(["id","name","altName","start","end","ethnicity","structure","place","occupation","note"])+"\n";
$(xml).find("person").each(function(index, elem) { // For each person
var els=[]; // Start fresh
els.push($(elem).attr("key")); // Get id
x=$(elem).find("nameGrp"); // Outer element
els.push($(x).find("name:first").text()); // Get name
x=$(elem).find("altNameGrp"); // Outer element
els.push($(x).find("name:first").text()); // Get first name
x=$(elem).find("existDates"); // Outer element
els.push($(x).find("beginDate").text()); // Get start
els.push($(x).find("endDate").text()); // Get end
els.push($(elem).find("ethnicity").text()); // Get ethnicity
a=$(elem).find("structureRef").attr("keyRef") ? $(elem).find("structureRef").attr("keyRef") : "";
a+=$(elem).find("structureRef").attr("role") ? ":"+$(elem).find("structureRef").attr("role") : "";
els.push(a); // Get structure
a=$(elem).find("geogPlaceRef").attr("keyRef") ? $(elem).find("geogPlaceRef").attr("keyRef") : "";
a+=$(elem).find("geogPlaceRef").attr("role") ? ":"+$(elem).find("geogPlaceRef").attr("role") : "";
els.push(a); // Get place
els.push($(elem).find("occupation").text()); // Get occupation
els.push($(elem).find("note").text()); // Get note
s+=MakeLine(els)+"\n";
});
$(xml).find("deity").each(function(index, elem) { // For each deity
var els=[]; // Start fresh
els.push($(elem).attr("key")); // Get id
x=$(elem).find("nameGrp"); // Outer element
els.push($(x).find("name:first").text()); // Get name
x=$(elem).find("altNameGrp"); // Outer element
els.push($(x).find("name:first").text()); // Get first name
x=$(elem).find("existDates"); // Outer element
els.push($(x).find("beginDate").text()); // Get start
els.push($(x).find("endDate").text()); // Get end
els.push($(elem).find("ethnicity").text()); // Get ethnicity
a=$(elem).find("structureRef").attr("keyRef") ? $(elem).find("structureRef").attr("keyRef") : "";
a+=$(elem).find("structureRef").attr("role") ? ":"+$(elem).find("structureRef").attr("role") : "";
els.push(a); // Get structure
a=$(elem).find("geogPlaceRef").attr("keyRef") ? $(elem).find("geogPlaceRef").attr("keyRef") : "";
a+=$(elem).find("geogPlaceRef").attr("role") ? ":"+$(elem).find("geogPlaceRef").attr("role") : "";
els.push(a); // Get place
els.push($(elem).find("type").text()); // Get type
els.push($(elem).find("note").text()); // Get note
s+=MakeLine(els)+"\n";
});
/*
var s=MakeLine(["id","name","altName","start","end","type","latLon","note"])+"\n";
$(xml).find("structure").each(function(index, elem) { // For each structure
var els=[]; // Start fresh
els.push($(elem).attr("key")); // Get id
x=$(elem).find("nameGrp"); // Outer element
els.push($(x).find("name:first").text()); // Get name
x=$(elem).find("altNameGrp"); // Outer element
els.push($(x).find("name:first").text()); // Get first name
x=$(elem).find("existDates"); // Outer element
els.push($(x).find("beginDate").text()); // Get start
els.push($(x).find("endDate").text()); // Get end
els.push($(elem).find("type").text()); // Get type
els.push(""); // Space for lat lom
els.push($(elem).find("note").text()); // Get note
s+=MakeLine(els)+"\n";
});
$(xml).find("geogPlace").each(function(index, elem) { // For each place
var els=[]; // Start fresh
els.push($(elem).attr("key")); // Get id
x=$(elem).find("nameGrp"); // Outer element
els.push($(x).find("name:first").text()); // Get name
x=$(elem).find("altNameGrp"); // Outer element
els.push($(x).find("name:first").text()); // Get first name
x=$(elem).find("existDates"); // Outer element
els.push($(x).find("beginDate").text()); // Get start
els.push($(x).find("endDate").text()); // Get end
els.push($(elem).find("type").text()); // Get type
els.push(""); // Space for lat lom
els.push($(elem).find("note").text()); // Get note
s+=MakeLine(els)+"\n";
});
*/
var s=MakeLine(["id","type","participants","start","end","structure","place","latLon","text","desc"])+"\n";
var id=1;
$(xml).find("episode").each(function(index, elem) { // For each place
var start="",end="",struc="",id=1,text="",p;
x=$(elem).find("date"); // Outer element
start=CDate($(x).find("beginDate").text()); // Get start
end=CDate($(x).find("endDate").text()); // Get end
struc=$(elem).find("structureRef").attr("keyRef"); // Get struct
$(elem).find("socialEvent").each(function(index, elem){ // For each social event
var els=[]; // Start fresh
els.push(id++); // Add id and inc
els.push("social"); // Add type
p="";
$(elem).find("participantNamed").each(function(index, elem) { // For each name participant
if (p) p+="," // Add comma
p+=$(elem).attr("keyRef"); // Add id
});
$(elem).find("participantPersonUnnamed").each(function(index, elem) { // For each name participant
if (p) p+="," // Add comma
p+=$(elem).find("occupation").text(); // Get occupation
});
els.push(p); // Add participants
els.push(start); // Add start
els.push(end); // Add end
els.push(struc); // Add struc
els.push($(elem).find("geogPlaceRef").attr("keyRef")); // Add place
desc=""; // Clar desc
$(elem).find("note").each(function(index, elem) { // For each note
if ($(elem).attr("type") == "text") // A text
text=$(elem).text(); // Get it
if ($(elem).attr("type") == "general") // A desc
desc=$(elem).text(); // Get it
});
els.push(text); // Add text
els.push(desc); // Add desc
s+=MakeLine(els)+"\n"; // Make line
});
$(elem).find("event").each(function(index, elem){ // For each event
var els=[]; // Start fresh
els.push(id++); // Add id and inc
els.push($(elem).find("class").text()); // Add class as type
p="";
$(elem).find("participantNamed").each(function(index, elem) { // For each name participant
if (p) p+="," // Add comma
p+=$(elem).attr("keyRef"); // Add id
});
$(elem).find("participantPersonUnnamed").each(function(index, elem) { // For each name participant
if (p) p+="," // Add comma
p+=$(elem).find("occupation").text(); // Get occupation
});
els.push(p); // Add participants
els.push(start); // Add start
els.push(end); // Add end
els.push(struc); // Add struc
els.push($(elem).find("geogPlaceRef").attr("keyRef")); // Add place
els.push(""); // Add latLon
desc=""; // Clar desc
$(elem).find("note").each(function(index, elem) { // For each note
if ($(elem).attr("type") == "text") // A text
text=$(elem).text(); // Get it
if ($(elem).attr("type") == "general") // A desc
desc=$(elem).text(); // Get it
});
els.push(text); // Add text
els.push(desc); // Add desc
s+=MakeLine(els)+"\n"; // Make line
});
});
trace(s)
}
function CDate(d)
{
var v=d.split(".")
v.length=Math.min(v.length,3)
if (!d) return "";
if (v[1] == "winter") v[1]=1;
if (v[1] == "spring") v[1]=4;
if (v[1] == "summer") v[1]=8;
if (v[1] == "fall") v[1]=11;
if (v[1]) v[1]=Math.min(Math.max(1,v[1]),12)
if (v[2]) v[2]=Math.min(Math.max(1,v[1]),28)
if (v.length == 1) return v[0];
if (v.length == 2) return v[1]+"/"+v[0];
if (v.length == 3) return v[2]+"/"+v[1]+"/"+v[0];
}
function MakeLine(els)
{
var i,str="";
for (i=0;i<els.length;++i) {
if (els[i] == undefined) els[i]="";
if (els[i] == "undefined") els[i]="";
if (els[i]) {
els[i]=""+els[i];
els[i]=els[i].replace(/[\n|\r|\n\r]/g,"");
els[i]=els[i].replace(/[^\x00-\x7F]/g,"");
els[i]=els[i].replace(/"/g,"\"");
}
str+="\""+els[i]+"\","
}
return (str.substr(0,str.length-1))
}
function trace(msg, p1, p2, p3, p4) // CONSOLE
{
if (p4 != undefined)
console.log(msg,p1,p2,p3,p4);
else if (p3 != undefined)
console.log(msg,p1,p2,p3);
else if (p2 != undefined)
console.log(msg,p1,p2);
else if (p1 != undefined)
console.log(msg,p1);
else
console.log(msg);
}
</script>
</body></html>