Dam*_*ien 5 xml parsing asp-classic
我是asp的新手,并且在接下来的几天里有一个截止日期.我从webservice响应中收到以下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>");
Run Code Online (Sandbox Code Playgroud)
我如何将这个xml解析为asp属性?
任何帮助是极大的赞赏
谢谢Damien
在更多的分析中,一些肥皂的东西也会被返回,因为aboce响应来自网络服务电话.我还能在下面使用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
Run Code Online (Sandbox Code Playgroud)
通过ASP,我认为你的意思是经典ASP?尝试:
Dim oXML, oNode, sKey, sValue
Set oXML = Server.CreateObject("MSXML2.DomDocument.4.0")
oXML.LoadXML(sXML)
For Each oNode In oXML.SelectNodes("/user_data/person_info/attribute")
sKey = oNode.GetAttribute("name")
sValue = oNode.Text
' Do something with these values here
Next
Set oXML = Nothing
Run Code Online (Sandbox Code Playgroud)
上面的代码假设您将XML放在一个名为sXML的变量中.如果您通过ServerXMLHttp请求使用它,您应该能够使用对象的ResponseXML属性代替上面的oXML,并完全跳过LoadXML步骤.