Solved

Get value from XML to ASP variable

Posted on 2006-07-07
5
375 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
ID: 17061344
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
ID: 17061366
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
ID: 17061406
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
ID: 17061492
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
ID: 17061540
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
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/…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 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