Solved

Get value from XML to ASP variable

Posted on 2006-07-07
5
376 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding Datediff to staistics page 2 62
SP to delete duplicates 15 73
If-Then-Else ASP problem 6 67
How to alternate between 2 messages until page closes in Classic ASP 8 38
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 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