-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataImport.js
53 lines (50 loc) · 2.06 KB
/
DataImport.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
FamilyTreeIndividual = {};
function xml2tree(url) {
var doc = getXml(url); if (!doc) return;
var indivs = {};
var indList = doc.getElementsByTagName("individual");
for (i=0; i < indList.length; i++) {
var ind = indList[i];
var F = function() {}; F.prototype = FamilyTreeIndividual;
var node = new F();
node.DOMNode = ind;
indivs[ind.getAttribute("id")] = node;
}
for (i in indivs) {
var ind = indivs[i];
ind.name = ind.DOMNode.getElementsByTagName("name")[0].textContent;
ind.name = ind.name.replace(/\//g,"");
ind.id = ind.DOMNode.getAttribute("id");
var n = ind.DOMNode.getElementsByTagName("note");
if (n && n[0]) { ind.note = n[0].textContent }
var f = ind.DOMNode.getElementsByTagName("father");
if (f && f[0]) { ind.father = indivs[f[0].getAttribute("ref")] }
var m = ind.DOMNode.getElementsByTagName("mother");
if (m && m[0]) { ind.mother = indivs[m[0].getAttribute("ref")] }
var s = ind.DOMNode.getElementsByTagName("spouse");
ind.spouses=[];
for (var x=0; x< s.length; x++){ var spice = s[x];
ind.spouses.push( indivs[spice.getAttribute("ref")] );
}
var s = ind.DOMNode.getElementsByTagName("sibling");
ind.siblings=[];
for (var x=0; x< s.length; x++){ var sib = s[x];
ind.siblings.push( indivs[sib.getAttribute("ref")] );
}
ind.offspring=[];
var c = ind.DOMNode.getElementsByTagName("child");
for (var x=0; x< c.length; x++){ var child = c[x];
ind.offspring.push( indivs[child.getAttribute("ref")] );
}
var b = ind.DOMNode.getElementsByTagName("born");
if (b[0] && b[0].getAttribute("date")) {
ind.born = b[0].getAttribute("date");
}
var d = ind.DOMNode.getElementsByTagName("died");
if (d[0] && d[0].getAttribute("died")) {
ind.born = b[0].getAttribute("date");
}
ind.sex = ind.DOMNode.getAttribute("sex");
}
return indivs;
}