Copy codeThe Code is as follows:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> untitled document </title>
<Script language = "javascript">
Function loadXML (handler ){
Var url = "employees. xml ";
If (document. implementation & document. implementation. createDocument ){
Var xmldoc = document. implementation. createDocument ("", "", null );
Xmldoc. onload = handler (xmldoc, url );
Xmldoc. load (url );
}
Else if (window. ActiveXObject ){
Var xmldoc = new ActiveXObject ("Microsoft. XMLDOM ");
Xmldoc. onreadystatechange = function (){
If (xmldoc. readyState = 4) handler (xmldoc, url );
}
Xmldoc. load (url );
}
}
Function makeTable (xmldoc, url ){
Var table = document. createElement ("table ");
Table. setAttribute ("border", "1 ");
Table. setAttribute ("width", "600 ");
Table. setAttribute ("class", "tab-content ");
Document. body. appendChild (table );
Var caption = "Employee Data from" + url;
Table. createCaption (). appendChild (document. createTextNode (caption ));
Var header = table. createTHead ();
Var headerrow = header. insertRow (0 );
Headerrow. insertCell (0). appendChild (document. createTextNode ("name "));
Headerrow. insertCell (1). appendChild (document. createTextNode ("Occupation "));
Headerrow. insertCell (2). appendChild (document. createTextNode ("salary "));
Var employees = xmldoc. getElementsByTagName ("employee ");
For (var I = 0; I <employees. length; I ++ ){
Var e = employees [I];
Var name = e. getAttribute ("name ");
Var job = e. getElementsByTagName ("job") [0]. firstChild. data;
Var salary = e. getElementsByTagName ("salary") [0]. firstChild. data;
Var row = table. insertRow (I + 1 );
Row. insertCell (0). appendChild (document. createTextNode (name ));
Row. insertCell (1). appendChild (document. createTextNode (job ));
Row. insertCell (2). appendChild (document. createTextNode (salary ));
}
}
</Script>
<Link href = "css/style.css" rel = "stylesheet" type = "text/css">
</Head>
<Body onLoad = "loadXML (makeTable)">
</Body>
</Html>
Copy codeThe Code is as follows:
<? Xml version = "1.0" encoding = "gb2312"?>
<Employees>
<Employee name = "J. Doe">
<Job> Programmer </job>
<Salary> 32768 </salary>
</Employee>
<Employee name = "A. Baker">
<Job> Sales </job>
<Salary> 70000 </salary>
</Employee>
<Employee name = "Big Cheese">
<Job> CEO </job>
<Salary> 100000 </salary>
</Employee>
</Employees>