Solved

Get value from XML to ASP variable

Posted on 2006-07-07
5
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error viewing ASP page 12 177
Asp in server side with Mssql Server 7 4 33
Two decimal 5 25
Can't select treeview node from iframe 2 33
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

735 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