asp怎么解析一个xml形式的字符串,不是一个xml文档,急,求助!!!
用asp解析
" <lottery_retu> <lottery_req> <md5> transid#status#memo#zgcpzx的密钥# </md5> <transid> 1003 </transid> <status> SUCC </status> <memo> </memo> </lottery_req> </lottery_retu> "
这个字符串,取 <transid> 的数据1003,请问怎么做???
------解决方案--------------------dom的 loadXML()
Dim oDoc, oNode
Set oDoc = CreateObject( "Msxml2.DOMDocument ")
With oDoc
.async = False
.loadXML( " <lottery_retu> <lottery_req> <md5> transid#status#memo#zgcpzx的密钥# </md5> <transid> 1003 </transid> <status> SUCC </status> <memo> </memo> </lottery_req> </lottery_retu> ")
If .parseError.errorCode <> 0 Then
response.write .parseError.reason
Else
Set oNode = .selectSingleNode( " "/lottery_retu/lottery_req/transid ")
If Not (oNode Is Nothing) Then response.write oNode.text
Set oNode = Nothing
End If
End With
Set oDoc = Nothing
------解决方案--------------------用dom.LoadXml(str)就可
------解决方案--------------------Set oNodes = .selectNodes( "/lottery_retu/lottery_req/transid ")
For i = 0 To oNodes.length - 1
response write oNodes(i).text
Next
------解决方案-------------------- <script type= "text/javascript ">
var text= " <lottery_retu> <lottery_req> <md5> transid#status#memo#zgcpzx 的密钥# </md5> <transid> 1003 </transid> <status> SUCC </status> <memo> </memo> </lottery_req> <lottery_req> <md5> 1234556# </md5> <transid> 1004 </transid> <status> SUCC </status> <memo> </memo> </lottery_req> </lottery_retu> ";
var doc=new ActiveXObject( "Microsoft.XMLDOM ");
doc.async= "false ";
doc.loadXML(text);
var x=doc.getElementsByTagName( "transid ");
for(var i=0;i <x.length;i++)
{
document.write(x.item(i).text+ " <br/> ");
}
</script>