Parse our portion of XML using ASP

Parse our portion of XML using ASP

am 15.01.2008 02:27:58 von Joey Martin

I'll try to make my explanation as thorough as possible.

I am trying to grab the value of the node that is returned.

MY CODE:
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
xmlhttp.open "POST"
Set xmldom = CreateObject("Microsoft.XMLDOM")
xmldom.loadXML thexml2
xmlhttp.send xmldom
response.Write(xmlhttp.responseText)

I left out some of the above code, but the code works and the results
are returned correctly. Here are the results I receive:




70
email@email.com





I want to grab the CLIENT_ID value, that's it. I need to set that as a
variable in my current code.

Please help. And thank you in advance.



*** Sent via Developersdex http://www.developersdex.com ***

Re: Parse our portion of XML using ASP

am 15.01.2008 10:08:08 von Anthony Jones

"Joey Martin" wrote in message
news:OoGfdXxVIHA.2000@TK2MSFTNGP05.phx.gbl...
> I'll try to make my explanation as thorough as possible.
>
> I am trying to grab the value of the node that is returned.
>
> MY CODE:
> Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
> xmlhttp.open "POST"
> Set xmldom = CreateObject("Microsoft.XMLDOM")
> xmldom.loadXML thexml2
> xmlhttp.send xmldom
> response.Write(xmlhttp.responseText)
>
> I left out some of the above code, but the code works and the results
> are returned correctly. Here are the results I receive:
>
>
>
>
> 70
> email@email.com
>

>

>

>
>
> I want to grab the CLIENT_ID value, that's it. I need to set that as a
> variable in my current code.
>
> Please help. And thank you in advance.
>


To 'grab' a value from XML you can use the DOMs selectSingleNode method:-

Set oElem = oSomeDOM.selectSingleNode("/response/clients/client/client_i d")
sID = oElem.text

It would be in your interest to tell us what it is you trying to achieve and
show use more of your code. For example you've left out the xmlhttp.open
call.

Do you control the remote site to which you are posting?
Does it ensure that the response content type is marked as an xml type?

Replace Microsoft.XMLHTTP with MSXML2.ServerXMLHTTP.3.0.

If all you are doing with the xmldom is passing it to send then consider
sending the string instead:-

xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=UTF-8"
xmlhttp.send thexml2

That way you avoid the significant xml parsing and DOM creation.

If you let us know more about what the code's purpose is we may be able to
give you a more complete answer.

--
Anthony Jones - MVP ASP/ASP.NET

Re: Parse our portion of XML using ASP

am 15.01.2008 14:18:12 von Joey Martin

I am "posting" my XML code and then given xml code back to me with
results based on my initial post. Here is my complete code:
<%
thexml2=thexml2 & ""
thexml2=thexml2 & ""
thexml2=thexml2 & " test@test.com"
thexml2=thexml2 & "
"
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")

xmlhttp.open "POST" ,"https://xxx.xxx.com/api/2.1/xml-in",False, "xxx"
, "X"
xmltext = thexml
Set xmldom = CreateObject("Microsoft.XMLDOM")
xmldom.loadXML thexml2
xmlhttp.send xmldom
response.Write(xmlhttp.responseText)


Returned is:




70
email@email.com





Again, all I care about it the Client ID value.



*** Sent via Developersdex http://www.developersdex.com ***

Re: Parse our portion of XML using ASP

am 15.01.2008 14:59:51 von Anthony Jones

"Joey Martin" wrote in message
news:uBIsVk3VIHA.4880@TK2MSFTNGP03.phx.gbl...
> I am "posting" my XML code and then given xml code back to me with
> results based on my initial post. Here is my complete code:
> <%
> thexml2=thexml2 & ""
> thexml2=thexml2 & ""
> thexml2=thexml2 & " test@test.com"
> thexml2=thexml2 & "
"
> Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
>
> xmlhttp.open "POST" ,"https://xxx.xxx.com/api/2.1/xml-in",False, "xxx"
> , "X"
> xmltext = thexml
> Set xmldom = CreateObject("Microsoft.XMLDOM")
> xmldom.loadXML thexml2
> xmlhttp.send xmldom
> response.Write(xmlhttp.responseText)
>
>
> Returned is:
>
>
>
>
> 70
> email@email.com
>

>

>

>
>
> Again, all I care about it the Client ID value.
>


Assuming the remote service has correctly set its Content-Type response
header then:-

sClientId = xmlhttp.ResponseXML.selectSingleNode("//client_id").Text

If that doesn't work (because ResponseXML is not set then try)

Dim oDOM : Set oDOM = CreateObject("MSXML2.DOMDocument.3.0")
oDOM.loadXML xmlhttp.responseText
sClientId = oDOM.selectSingleNode("//client_id").Text


--
Anthony Jones - MVP ASP/ASP.NET