我是ASP的新手,并且在接下来的几天有最后期限。
我从Web服务响应中收到以下xml。
print("<?xml version="1.0" encoding="UTF-8"?>
<user_data>
<execution_status>0</execution_status>
<row_count>1</row_count>
<txn_id>stuetd678</txn_id>
<person_info>
<attribute name="firstname">john</attribute>
<attribute name="lastname">doe</attribute>
<attribute name="emailaddress">john.doe@johnmail.com</attribute>
</person_info>
</user_data>");
我如何将这个xml解析为asp属性?
任何帮助是极大的赞赏
谢谢
达米安
在更多分析中,由于重新响应来自Web服务调用,因此还返回了一些消息。我仍然可以使用下面的lukes代码吗?
最佳答案
您需要阅读有关MSXML解析器的信息。这是一个很好的多合一示例http://oreilly.com/pub/h/466的链接
对XPath的一些阅读也会有所帮助。您可以在MSDN中获得所需的所有信息。
出于聚合目的,从Luke窃取了很好的答复中的代码:
Dim oXML, oNode, sKey, sValue
Set oXML = Server.CreateObject("MSXML2.DomDocument.6.0") 'creating the parser object
oXML.LoadXML(sXML) 'loading the XML from the string
For Each oNode In oXML.SelectNodes("/user_data/person_info/attribute")
sKey = oNode.GetAttribute("name")
sValue = oNode.Text
Select Case sKey
Case "execution_status"
... 'do something with the tag value
Case else
... 'unknown tag
End Select
Next
Set oXML = Nothing
关于xml - ASP XML解析,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/94689/