-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml-html.js
More file actions
148 lines (141 loc) · 4.01 KB
/
xml-html.js
File metadata and controls
148 lines (141 loc) · 4.01 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
var listOfValues = [];
var checkForFirstRun = 0;
var nodeElement = 1;
var totalServers = 0;
var selectedOption = "";
var listOfAttributesSelectedIndex = 1;
var listOfAttributesInDiv = [];
var whereToInsert = '';
var xmlFilePath = '';
//get xml dat from xml file
var catchXml = function(){
var xhttp = "";
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
loader(this, listOfAttributesInDiv);
}
};
xhttp.open('GET',xmlFilePath,true);
xhttp.send();
};
//get values from xml and add pass it to select maker
function loader(xml, listOfAttributes){
var xmlDoc = xml.responseXML;
var i = 0;
for(var j=0; j<listOfAttributes.length; j++){
while(typeof(xmlDoc.getElementsByTagName(listOfAttributes[j] + nodeElement)[i].childNodes[0].nodeValue) !== undefined)
{
listOfValues.push(xmlDoc.getElementsByTagName(listOfAttributes[j] + nodeElement)[i].childNodes[0].nodeValue);
try{
if(xmlDoc.getElementsByTagName(listOfAttributes[j] + nodeElement)[i+1].childNodes[0].nodeValue === undefined){
}
}
catch(e){
break;
}
i++;
totalServers++;
}
if(checkForFirstRun == 0)
{
listOfValues = [];
var l = 1;
while(typeof(xmlDoc.getElementsByTagName(listOfAttributes[0] + l)[0].childNodes[0].nodeValue) !== undefined)
{
listOfValues.push(xmlDoc.getElementsByTagName(listOfAttributes[0] + l)[0].childNodes[0].nodeValue);
try{
if(xmlDoc.getElementsByTagName(listOfAttributes[0] + (l+1))[0].childNodes[0].nodeValue === undefined){
}
}
catch(e){
break;
}
l++;
}
checkForFirstRun = 1;
insertDiv(listOfValues);
l = 1;
}
else
{
checkForFirstRun = 11;
insertDiv(listOfValues);
}
listOfValues = [];
i = 0;
}
}
//make select dropdown from the xml data passed in listofelements
function insertDiv(listOfElements){
var div = document.getElementById(whereToInsert);
var select = document.createElement('select');
if(checkForFirstRun == 1){
select.name = listOfAttributesInDiv[0];
select.id = listOfAttributesInDiv[0];
}
if(checkForFirstRun == 11){
select.name = listOfAttributesInDiv[listOfAttributesSelectedIndex];
select.id = listOfAttributesInDiv[listOfAttributesSelectedIndex];
checkForFirstRun = 1;
listOfAttributesSelectedIndex++;
}
checkForFirstRun = 2;
for(var k=0; k<listOfElements.length; k++)
{
if(listOfElements[k] == selectedOption)
{
var option = new Option('text', 'value', false, true);
option.value = listOfElements[k];
option.text = listOfElements[k];
select.appendChild(option);
}
else
{
var option = new Option('text', 'value', false, false);
option.value = listOfElements[k];
option.text = listOfElements[k];
select.appendChild(option);
}
}
div.appendChild(select);
if(checkForFirstRun == 2){
checkForFirstRun = 3;
changeInServer();
}
}
//if the main node is changed... change the whole dropdown
function changeInServer(){
document.getElementById(listOfAttributesInDiv[0]).addEventListener('change',function(){
checkForFirstRun = 0;
listOfAttributesSelectedIndex = 1;
try{
var e = document.getElementById(listOfAttributesInDiv[0]);
selectedOption = e.options[e.selectedIndex].text;
if(nodeElement <= totalServers){
nodeElement = e.selectedIndex + 1;
document.getElementById(whereToInsert).innerHTML = "";
catchXml();
}
else
{
nodeElement = 1;
}
}
catch(e){}
});
checkForFirstRun = 1;
}
//data => xml tags , where to insert in html , xmlfilepath
function addXmlData(data, insertWhereInHtml, path){
for(var i=0; i<data.length; i++){
listOfAttributesInDiv.push(data[i]);
}
whereToInsert = insertWhereInHtml;
xmlFilePath = path;
catchXml();
}