Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Parse our portion of XML using ASP

Reply
Thread Tools

Parse our portion of XML using ASP

 
 
Joey Martin
Guest
Posts: n/a
 
      01-15-2008
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>(E-Mail Removed)</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.



*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Anthony Jones
Guest
Posts: n/a
 
      01-15-2008
"Joey Martin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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>(E-Mail Removed)</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.

--
Anthony Jones - MVP ASP/ASP.NET


 
Reply With Quote
 
 
 
 
Joey Martin
Guest
Posts: n/a
 
      01-15-2008
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>(E-Mail Removed)</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>(E-Mail Removed)</username>
</client>
</clients>
</response>


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



*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
Anthony Jones
Guest
Posts: n/a
 
      01-15-2008
"Joey Martin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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>(E-Mail Removed)</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>(E-Mail Removed)</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


--
Anthony Jones - MVP ASP/ASP.NET


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading only a specific portion of XML file. Savvoulidis Iordanis ASP .Net 3 12-15-2009 09:18 PM
Can I have 2 IP addresses on our internal interface on our cisco pix firewall bgamblin@spvg.com Cisco 1 09-08-2005 08:54 PM
How do we stamp our names onto our photos? Kim Digital Photography 6 01-06-2005 06:12 AM
Where do we get our MCDST symbols to put in our outlook signature? sb20056 MCDST 1 04-09-2004 09:40 PM
equal sign in value portion of xml tag johndesp XML 1 01-19-2004 06:33 PM



Advertisments