在javascript中将xml记录集转换为数组

时间:2011-08-25 05:15:37

标签: javascript

如何将使用javascript加载的xml记录集转换为javascript数组...

 <script language="JavaScript">
 function load() {
var xmlDso=myXML.XMLDocument;
xmlDso.load("myxxml.xml");
var memberset=myXML.recordset;

 }
 </script>

在上面如果我想将memberet转换为javascript数组以进一步使用怎么办?

<html>
<head>
<title>XML DSO-example3.htm</title>
 <script language="JavaScript">
  function load() {
var xmlDso=myXML.XMLDocument;
xmlDso.load("myxxml.xml");
var memberset=myXML.recordset;
                                  here i need to change recordset to array
 }
</script>
</head>

<body bgcolor="#FFFFFF" onLoad="load()">

<object id="myXML" CLASSID="clsid:550dda30-0541-11d2-9ca9-0060b0ec3d39" width="0" 

height="0"></object>

<table datasrc="#myXML" border="1">
<thead> 
<th>id</th>   
<th>name</th>  
<th>collagename</th>
<th>committedAmount</th> 
<th>defaulted</th>  
<th>total</th>  
</thead> 
<tr>    
<td><div datafld="id"></div></td>  
<td><div datafld="name"></div></td>  
<td><div datafld="collagename"></div></td>  
<td><div datafld="committedAmount"></div></td>  
<td><div datafld="defaulted"></div></td>  
<td><div datafld="total"></div></td>  
</tr>  
</table>  

</body> 
</html>  

1 个答案:

答案 0 :(得分:1)

检查这个答案,如何在JavaScript中解析XML:

XML parsing of a variable string in JavaScript

但是,我会重新考虑设计。而不是使用XML请求/返回数据,使用JSON更方便。