Asp XML Parsing

I am new to asp and have a deadline in the next few days. I get the following xml from web service response.

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>");

How can I parse this xml in asp attributes?

Any help is appreciated

Thanks Damien

With further analysis, some soap elements are also returned, since the aboce response comes from a web service call. can i still use the lukes code below?

+5
source share
3 answers

You need to read about the MSXML parser. Here is a link to a good all-in-one example http://oreilly.com/pub/h/466

Some XPath readings will also help. You can get all the necessary information on 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
+9

ASP , Classic 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

, XML sXML. ServerXMLHttp, ResponseXML oXML LoadXML.

+6

You can try loading xml into an xmldocument object and then parse it using its methods.

0
source

All Articles