Parse our portion of XML using ASP

J

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:
<?xml version="1.0" encoding="utf-8"?>
<response xmlns="xxxxxxx.com" status="ok">
<clients page="1" per_page="25" pages="1" total="1">
<client>
<client_id>70</client_id>
<username>[email protected]</username>
</client>
</clients>
</response>


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.
 
A

Anthony Jones

Joey Martin said:
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:
<?xml version="1.0" encoding="utf-8"?>
<response xmlns="xxxxxxx.com" status="ok">
<clients page="1" per_page="25" pages="1" total="1">
<client>
<client_id>70</client_id>
<username>[email protected]</username>
</client>
</clients>
</response>


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_id")
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.
 
J

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 & "<?xml version='1.0' encoding='utf-8'?>"
thexml2=thexml2 & "<request method='client.list'>"
thexml2=thexml2 & " <email>[email protected]</email>"
thexml2=thexml2 & "</request>"
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:
<?xml version="1.0" encoding="utf-8"?>
<response xmlns="xxxxxxx.com" status="ok">
<clients page="1" per_page="25" pages="1" total="1">
<client>
<client_id>70</client_id>
<username>[email protected]</username>
</client>
</clients>
</response>


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

Anthony Jones

Joey Martin said:
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 & "<?xml version='1.0' encoding='utf-8'?>"
thexml2=thexml2 & "<request method='client.list'>"
thexml2=thexml2 & " <email>[email protected]</email>"
thexml2=thexml2 & "</request>"
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:
<?xml version="1.0" encoding="utf-8"?>
<response xmlns="xxxxxxx.com" status="ok">
<clients page="1" per_page="25" pages="1" total="1">
<client>
<client_id>70</client_id>
<username>[email protected]</username>
</client>
</clients>
</response>


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top