-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW4.html
184 lines (167 loc) · 5.5 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<html>
<head>
<style>
h3
{
text-align: center;
}
form
{
text-align: center;
}
</style>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>View CompanyList</title>
<script type="text/javascript">
function generateHTML(xmlDoc)
{
flag = 0;
ELEMENT_NODE = 1; // MS parser doesn't define Node.ELEMENT_NODE
root=xmlDoc.DocumentElement;
html_text="<html><head><title>XML Parse Result</title></head><body>";
html_text+="<table border='2' width='50%' height='50%' align='center'>";
company = xmlDoc.getElementsByTagName("Row");
if(company.length == 1)
{
alert("NO COMPANY LISTED IN XML FILE");
flag = 1;
}
companyNodeList=company.item(0).childNodes;
html_text+="<tbody>";
html_text+="<tr>";
x=0; y=0;
// output the headers
for(i=0;i<companyNodeList.length;i++)
{
if(companyNodeList.item(i).nodeType==ELEMENT_NODE)
{
header=companyNodeList.item(i).firstChild.nodeValue;
html_text+="<th>"+header+"</th>";
}
}
html_text+="</tr>";
// output out the values
for(i=1;i<company.length;i++) //do for all planes
{
companyNodeList=company.item(i).childNodes; //get properties of a plane
html_text+="<tr>"; //start a new row of the output table
for(j=0;j<companyNodeList.length;j++)
{
if(companyNodeList.item(j).nodeType==ELEMENT_NODE)
{
if(companyNodeList.item(j).firstChild == null || companyNodeList.item(j).firstChild.nodeValue.trim().length == 0)
{
html_text += "<td>NA</td>";
}
else if(companyNodeList.item(j).nodeName=="Logo")
{//handle images separately
html_text+="<td><img src='"+companyNodeList.item(j).firstChild.nodeValue+"' width= 60 height=60'></td>";
}
else if(companyNodeList.item(j).nodeName=="HomePage")
{
html_text+="<td><a href='"+companyNodeList.item(j).firstChild.nodeValue+"'>link to company</a></td>";
}
else
{
html_text+="<td>"+companyNodeList.item(j).firstChild.nodeValue+"</td>";
}
}
}
html_text+="</tr>";
}
html_text+="</tbody>";
html_text+="</table>";
html_text+="<NOSCRIPT>";
html_text+="</bo";
html_text+="dy></html>";
}
function loadXML(url)
{
xmlDoc = null;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
try
{
xmlhttp.open("GET",url,false);
xmlhttp.send();
}
catch(err)
{
if(xmlhttp.status == 404 || xmlhttp.status == 400)
alert("FILE NOT FOUND");
}
xmlDoc=xmlhttp.responseXML;
return xmlDoc;
}
function viewXML(what)
{
var URL = what.URL.value;
if(URL == "")
alert("FILE NAME NOT SPECIFIED");
else
{
xmlDoc = loadXML(URL);
if (window.ActiveXObject) //if IE, simply execute script (due to async prop).
{
if (xmlDoc==null)
{
alert("FILE NOT FOUND");
}
else if (xmlDoc.documentElement.nodeName == "parsererror")
{
alert("ERROR IN XML FILE");
}
else
{
generateHTML(xmlDoc);
if(flag !=1)
{
hWin = window.open("", "Assignment4", "scrollbars=yes,height=800,width=610");
hWin.document.write(html_text);
hWin.document.close();
}
}
}
else //else if FF, execute script once XML object has loaded
{
if (xmlDoc==null)
{
alert("FILE NOT FOUND");
}
else if (xmlDoc.documentElement.nodeName == "parsererror")
{
alert("ERROR IN XML FILE");
}
else
{
xmlDoc.onload=generateHTML(xmlDoc);
if(flag!=1)
{
hWin = window.open("", "Assignment4", "scrollbars=yes,height=800,width=610");
hWin.document.write(html_text);
hWin.document.close();
}
}
}
}
hWin.document.close();
}
</script>
</head>
<body>
<h3>Enter URL for Company List XML file</h3>
<form name="myform" method="POST" id="location" >
<input type="text" name="URL" maxlength="45" size="50" value="companylist.xml" />
<br />
<br>
<input type="button" name="submit" value="Submit Query" onclick = "viewXML(this.form)"/>
</form>
<NOSCRIPT>
</body>
</html>