Solved

Get value from XML to ASP variable

Posted on 2006-07-07
5
372 Views
Last Modified: 2008-01-16
In my ASP I request data with XML over HTTP post. The returned result is also in XML. Based on the returned value in my ASP I need to run different functions. However I cant get the value in to an ASP variable.

After I do HTTP Post I do the following:
Response.Write xml.responseText

Which then displays this on the scrren:
<?xml version="1.0" encoding="UTF-8" ?>
- <connector_ret>
- <function name="sql_get_int" id="iEmailExist">
  <ret_val name="rv" type="integer">2076</ret_val>
  </function>
  </connector_ret>

Now I want the integer "2076" that was returned in a variable.

So I can do:

If Myvalue = '' Then
  RUN Function
Else
   Run another function
End If

Thansk

0
Comment
Question by:apirnia
  • 3
5 Comments
 
LVL 14

Assisted Solution

by:dfu23
dfu23 earned 200 total points
Comment Utility
a cheap way to do it is just to check within the string for something that you know will or will not be there ... if it is there then extract the part you want and do what you need otherwise do the other:

Dim ResponseText
ResponseText = xml.responseText

Dim SearchString
SearchString = "<ret_val name=""rv"" type=""integer"">"

Dim EndString
EndString = "</ret_val>"

Dim FoundNumber

If InStr(ResponseText, SearchString) = 0 Then ' Not Found
  ' RUN Function
Else ' Found - Attempt to extract the number
  FoundNumber = Mid(ResponseText, InStr(ResponseText, SearchString) + Len(SearchString), InStr(ResponseText, EndString) - InStr(ResponseText, SearchString) + Len(SearchString))
  ' Run Another Function
End If
0
 
LVL 14

Expert Comment

by:dfu23
Comment Utility
Another (better) way to do this would be to load your XML into an actual XML object and get to the data programmatically using its built in functionality ...
0
 
LVL 9

Author Comment

by:apirnia
Comment Utility
I think the secound way you mentioned is the way I should go, but I dont know how to do it. Is it by using the XML DOME Object?
0
 
LVL 14

Expert Comment

by:dfu23
Comment Utility
VBScript:
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")

For Reference:
http://devguru.com/technologies/xml_dom/15602.asp

Document.GetElementsByTagName Reference (should be handy):
http://devguru.com/technologies/xml_dom/15803.asp
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 300 total points
Comment Utility
Something like:

    Set doc = Server.CreateObject("MSXML2.DOMDocument.4.0")
    If doc.LoadXML(xml.responseXML) Then
        Set node = doc.selectSingleNode("//ret_val")
        If Not node Is Nothing Then
           val = node.Text
        End If
    End If
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now