-
Notifications
You must be signed in to change notification settings - Fork 0
/
HW4.html
168 lines (141 loc) · 5.61 KB
/
HW4.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
<!DOCTYPE HTML>
<HTML lang="en">
<HEAD>
<meta charset="utf-8">
<meta name="description" content="Filiming Location Search">
<TITLE> XML PARSER </TITLE>
<script type="text/javascript">
var resultWindow = null;
function getXML(){
var myLink=document.getElementById('link').value.trim();;
if(myLink=="" || myLink == null){
alert("Please enter a file name");
document.getElementById('link').value='';
return false;
}
var str=myLink;
var url= myLink;
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXobject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET",url,false);
xmlhttp.send();
if(xmlhttp.status==404){
alert('File does not exist, please check the requested file name/path again!');
return false;
}
xmlDoc=xmlhttp.responseXML;
if(xmlDoc==null){
alert('Error in XML file');
return false;
}
rows=xmlDoc.getElementsByTagName("Row");
if(rows.length==0){
alert('No Airline Companies');
return false;
}
var flag=false;
for(var z=0;z<rows.length;z++){
if(rows[z].childElementCount!=0){
break;
}
else{
alert('No Airline Companies');
return false;
}
}
if(!resultWindow || resultWindow.closed){
resultWindow= window.open("", "", "width=1000px,height=700px");
}
else{
resultWindow.close();
resultWindow= window.open("", "", "width=1000px,height=700px");
}
xmlDoc.onload=generateHTML(xmlDoc);
return false;
}
function generateHTML(xmlDoc){
ELEMENT_NODE = 1;
root=xmlDoc.DocumentElement;
html_text="<html><head><title>XML Parse Result</title></head><body>";
html_text+="<table border='2'>";
headers=xmlDoc.getElementsByTagName("Header");
headersList=headers.item(0).childNodes;
if(headersList.length==0){
alert('No Airline Companies');
return false;
}
html_text+="<tr>";
for(j=0;j<headersList.length;j++){
if(headersList.item(j).nodeType==ELEMENT_NODE && headersList.item(j).firstChild==null){
html_text+="<th></th>";
}
else if(headersList.item(j).nodeType==ELEMENT_NODE){
html_text+="<th>"+headersList.item(j).firstChild.nodeValue.trim()+"</th>";
}
}
html_text+="</tr>";
rows=xmlDoc.getElementsByTagName("Row");
for( k=0; k<rows.length; k++){
rowList=rows.item(k).childNodes;
html_text+="<tr>";
for(j=0;j<rowList.length;j++){
if(rowList.item(j).nodeType==ELEMENT_NODE){
if(rowList.item(j).tagName=="Hubs"){
html_text+="<td><ul>";
for(h=0; h<rowList.item(j).children.length;h++){
if(rowList.item(j).children[h].firstChild==null){
html_text+="<li></li>";
}
if(rowList.item(j).children[h].firstChild!=null){
if(h==0)
html_text+="<b><li>"+rowList.item(j).children[h].firstChild.nodeValue.trim()+"</li></b>";
else
html_text+="<li>"+rowList.item(j).children[h].firstChild.nodeValue.trim()+"</li>";
}
}
html_text+="</ul></td>";
}
else if(rowList.item(j).tagName=="HomePage"){
html_text+="<td><a href="+rowList.item(j).firstChild.nodeValue.trim()+">"+rowList.item(j).firstChild.nodeValue.trim()+"</a></td>";
}
else if(rowList.item(j).tagName=="Plane"){
html_text+="<td><img src="+rowList.item(j).firstChild.nodeValue.trim()+" style="+"height:200px;widht:200px;"+"></img></td>";
}
else if(rowList.item(j).firstChild==null)
html_text+="<td>"+ " "+"</td>";
else if (rowList.item(j).firstChild!=null)
html_text+="<td>"+rowList.item(j).firstChild.nodeValue.trim()+"</td>";
}
}
html_text+="</tr>";
}
html_text+="<tbody>";
html_text+="<tr>";
x=0; y=0;
html_text+="</tr>";
html_text+="</tbody>"; html_text+="</table>";
html_text+="<noscript>";
html_text+="</body></html>";
//resultWindow.document.write(html_text);
resultWindow.document.body.innerHTML=html_text;
//popup.document.body.innerHTML
return false;
}
</script>
</HEAD>
<BODY>
<form method="GET" onsubmit=" return getXML();">
<div id="mainDiv" style="margin-left: 40%; margin-top: 10%;">
<p style="font-weight: bold;">Enter URL for Airline List XML File</p>
<input style="margin-left: 5%" id="link" type="text" value="" onkeydown = "if (event.keyCode == 13) document.getElementById('button').click()"/>
<!-- <input id="button" type="button" value="Submit Query" onclick="getXML(document.getElementById('link'))";></input> -->
<br><br>
<input style="align:center;margin-left: 9%;height:22px; background: #a3a2a1; border: 0.5px solid #a1a1a1; border-radius: 5px;" id="button" type="submit" value="Submit Query" ></input>
</div>
</form>
<noscript>
</BODY>