Solved

Get value from XML to ASP variable

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Button to go back 3 44
href return to normal window 5 43
Debugging Html 8 43
Asp response.write to clients 6 46
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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