JS reads XML file data and displays data in table format (compatible with IE and Firefox), xmltable
This document describes how to use JavaScript to read XML file data and display data in table format. We will share this with you for your reference. The details are as follows:
First look at the xml file:
<? Xml version = "1.0" standalone = "yes"?> <Student> <stuinfo> <stuName> Zhang qiuli </stuName> <stuSex> female </stuSex> <stuAge> 18 </stuAge> </stuinfo> <stuName> Li wencai </stuName> <stuSex> male </stuSex> <stuAge> 31 </stuAge> </stuinfo> <stuName> Li siwen </stuName> <stuSex> male </stuSex> <stuAge> 22 </stuAge> </stuinfo> <stuName> Ma Ying </stuName> <stuSex> female </stuSex> <stuAge> 25 </stuAge> </stuinfo> <stuName> sun honglei </stuName> <stuSex> male </stuSex> <stuAge> 32 </stuAge> </stuinfo> <stuinfo> <stuName> Ouyang junxiong </stuName> <stuSex> male </stuSex> <stuAge> 28 </stuAge> </stuinfo> <stuName> Jiang Lin </stuName> <stuSex> female </stuSex> <stuAge> 23 </stuAge> </stuinfo> <stuName> small </stuName> <stuSex> female </stuSex> <stuAge> 22 </stuAge> </stuinfo> </student>
Aspx page code:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "Get database data to generate XML. aspx. cs "Inherits =" Chapter1. get database data to generate XML "%> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
The above JS operations mainly avoid using childNodes (because in Firefox, sometimes childNodes [0] gets "\ n" instead of the first subnode we want, I can try it myself, but I have encountered this situation) to make it compatible with IE and Firefox. I did not try other browsers.