日期:2014-05-17  浏览次数:20902 次

如何用asp将这样的xml转换成表格
<?xml   version= "1.0 "   encoding= "GB2312 "   standalone= "yes "?>
<History   Type= "BC "   TotalNum= "151973 "   QueryFrom= "2007-05-22   08:39:05 "   QueryTo= "2007-06-01   08:39:08 "   TotalPages= "760 "  

CurrentPage= "1 "   CurrentNum= "200 "   VaildFrom= "2007-05-29   16:34:48 "   VaildTo= "2007-06-01   08:39:08 ">
<Data   Time= "2007-05-29   16:34:48 "   Strength= "88.0 "   ModLeft= "0 "   ModRight= "0 "/>
<Data   Time= "2007-05-29   17:10:18 "   Strength= "88.0 "   ModLeft= "26 "   ModRight= "29 "/>
<Data   Time= "2007-05-29   17:10:19 "   Strength= "85.0 "   ModLeft= "27 "   ModRight= "31 "/>
<Data   Time= "2007-05-29   17:10:20 "   Strength= "86.0 "   ModLeft= "29 "   ModRight= "31 "/>
</History>


------解决方案--------------------
<%

Set xmlDoc = CreateObject( "Msxml2.DOMDocument ")
xmlDoc.async = False
xmlDoc.Load Server.MapPath( "abc.xml ")
If (xmlDoc.parseError.errorCode <> 0) Then
Response.Write xmlDoc.parseError.reason
Response.End
Else
Set oNodes = xmlDoc.selectNodes( "/History/Data ")
End If
%>

<table>
<tr>
<td> Time </td>
<td> Strength </td>
<td> ModLeft </td>
<td> ModRight </td>
</tr>
<%
s = " "
For i=0 To oNodes.length-1
s = s & " <tr> "
s = s & " <td> " & oNodes(i).getAttribute( "Time ")& " </td> "
s = s & " <td> " & oNodes(i).getAttribute( "Strength ")& " </td> "
s = s & " <td> " & oNodes(i).getAttribute( "ModLeft ")& " </td> "
s = s & " <td> " & oNodes(i).getAttribute( "ModRight ")& " </td> "
s = s & " </tr> "
Next
Response.Write s
%>
</table>