Solved

XML and ASP

Posted on 2006-06-21
4
486 Views
Last Modified: 2008-02-07
Ok i'm using XML-RPC to get photos throught the Flickr API, heres my code:

-------------------------------------------

      'Create XML
      Dim xmlHttp, xmlDoc, xmlDOM, invnum       
      xmlDoc = "<?xml version='1.0'?><!DOCTYPE Request.dtd><methodCall>"  
      xmlDoc = xmlDoc & "<methodName>flickr.photosets.getPhotos</methodName>"
      xmlDoc = xmlDoc & "<params><param><value><struct>"
            xmlDoc = xmlDoc & "<member>"
                  xmlDoc = xmlDoc & "<name>api_key</name>"
                  xmlDoc = xmlDoc & "<value><string>h9wger8gasuoidb98q3wri0nb2q39rh1</string></value>"
            xmlDoc = xmlDoc & "</member>"
            xmlDoc = xmlDoc & "<member>"
                  xmlDoc = xmlDoc & "<name>photoset_id</name>"
                  xmlDoc = xmlDoc & "<value><string>72157594173596241</string></value>"
            xmlDoc = xmlDoc & "</member>"
      xmlDoc = xmlDoc & "</struct></value></param></params></methodCall>"       
        
      Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
      xmlHttp.open "POST", "http://www.flickr.com/services/xmlrpc/", false
      
      xmlHttp.send xmlDoc
      dim flickrResponse, photoset
      flickrResponse = Replace(xmlHttp.responseText,"&quot;","'")
      flickrResponse = Replace(flickrResponse,"&lt;","<")
      flickrResponse = Replace(flickrResponse,"&gt;",">")
      
      Response.write("<xmp>" & flickrResponse & "</xmp>")         
      
      Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument")
      
      If Err Then      
            errstr =  "Error: " & Err.Description & "; "
            Err.Clear()      
      End If

      xmlDOM.async = False
      
      If xmlDOM.loadxml(xmlHttp.responseText) Then      
            'Response.write("<xmp>" & xmlDOM.xml & "</xmp>")
            photoset = Trim(xmlDOM.getElementsByTagName("string").item(0).text)
      Else      
            errStr =  "Error: " & xmlDOM.parseError.reason  & "; "
      End If
      
      response.Write("<br>Item: " & photoset)
      
      'Cleanup XML
      xmlDoc = ""
      Set xmlHttp = nothing
      Set xmlDOM = Nothing

----------------------------------------------------------------

You can see it working here http://www.boozesandiego.com/photos.asp

You can see that i can post the XML and get a response ok. The problem is how can i extract values from the response? I need to put For each photo i need the ID, Secret, Server and Title values. How can i do this?
0
Comment
Question by:alex_wareing
[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
  • 2
  • 2
4 Comments
 
LVL 25

Expert Comment

by:clockwatcher
ID: 16956730
Give this a try:

<%
  'Create XML
     Dim xmlHttp, xmlDoc, xmlDOM, invnum      
     xmlDoc = "<?xml version='1.0'?><!DOCTYPE Request.dtd><methodCall>"  
     xmlDoc = xmlDoc & "<methodName>flickr.photosets.getPhotos</methodName>"
     xmlDoc = xmlDoc & "<params><param><value><struct>"
          xmlDoc = xmlDoc & "<member>"
               xmlDoc = xmlDoc & "<name>api_key</name>"
               xmlDoc = xmlDoc & "<value><string>h9wger8gasuoidb98q3wri0nb2q39rh1</string></value>"
          xmlDoc = xmlDoc & "</member>"
          xmlDoc = xmlDoc & "<member>"
               xmlDoc = xmlDoc & "<name>photoset_id</name>"
               xmlDoc = xmlDoc & "<value><string>72157594173596241</string></value>"
          xmlDoc = xmlDoc & "</member>"
     xmlDoc = xmlDoc & "</struct></value></param></params></methodCall>"      
       
     Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
     xmlHttp.open "POST", "http://www.flickr.com/services/xmlrpc/", false
     
     xmlHttp.send xmlDoc
     dim flickrResponse, photoset

     set xmlDOM =  xmlHttp.ResponseXML
     response.write "<xmp>" & xmlDOM.xml & "</xmp>"
     
     for each node in xmlDOM.getElementsByTagName("photo")
         response.write "ID: " & node.getAttribute("id") & "<BR>"
         response.write "secret: " & node.getAttribute("secret") & "<BR>"
     next

     'Cleanup XML
     Set xmlHttp = nothing
     Set xmlDOM = Nothing
%>
0
 

Author Comment

by:alex_wareing
ID: 16962768
Ok so i tried your code like this:
<%
      'Create XML
      Dim xmlHttp, xmlDoc, xmlDOM, invnum       
      xmlDoc = "<?xml version='1.0'?><!DOCTYPE Request.dtd><methodCall>"  
      xmlDoc = xmlDoc & "<methodName>flickr.photosets.getPhotos</methodName>"
      xmlDoc = xmlDoc & "<params><param><value><struct>"
            xmlDoc = xmlDoc & "<member>"
                  xmlDoc = xmlDoc & "<name>api_key</name>"
                  xmlDoc = xmlDoc & "<value><string>insert_key_string_value_here</string></value>"
            xmlDoc = xmlDoc & "</member>"
            xmlDoc = xmlDoc & "<member>"
                  xmlDoc = xmlDoc & "<name>photoset_id</name>"
                  xmlDoc = xmlDoc & "<value><string>72157594173214252</string></value>"
            xmlDoc = xmlDoc & "</member>"
      xmlDoc = xmlDoc & "</struct></value></param></params></methodCall>"       
        
      Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
      xmlHttp.open "POST", "http://www.flickr.com/services/xmlrpc/", false
      
      xmlHttp.send xmlDoc
      dim flickrResponse, photoset, node
      
      set xmlDOM =  xmlHttp.ResponseXML
      response.write "<xmp>" & xmlDOM.xml & "</xmp>"
      
      for each node in xmlDOM.getElementsByTagName("photo")
            response.write "ID: " & node.getAttribute("id") & "<BR>"
            response.write "secret: " & node.getAttribute("secret") & "<BR>"
      next
      
      response.Write("<br><br>Page End")
      
      'Cleanup XML
      Set xmlHttp = nothing
      Set xmlDOM = Nothing
      
%>
You can see the results at http://www.boozesandiego.com/photos.asp

It still doesn't get the info from the XML
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
ID: 16966031
I didn't realize the response escaped the less than and greater than.  Try this.  It's back closer to what you had:

<%
     'Create XML
     Dim xmlHttp, xmlDoc, xmlDOM, invnum      
     xmlDoc = "<?xml version='1.0'?><!DOCTYPE Request.dtd><methodCall>"  
     xmlDoc = xmlDoc & "<methodName>flickr.photosets.getPhotos</methodName>"
     xmlDoc = xmlDoc & "<params><param><value><struct>"
          xmlDoc = xmlDoc & "<member>"
               xmlDoc = xmlDoc & "<name>api_key</name>"
               xmlDoc = xmlDoc & "<value><string>insert_key_string_value_here</string></value>"
          xmlDoc = xmlDoc & "</member>"
          xmlDoc = xmlDoc & "<member>"
               xmlDoc = xmlDoc & "<name>photoset_id</name>"
               xmlDoc = xmlDoc & "<value><string>72157594173214252</string></value>"
          xmlDoc = xmlDoc & "</member>"
     xmlDoc = xmlDoc & "</struct></value></param></params></methodCall>"      
       
     Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
     xmlHttp.open "POST", "http://www.flickr.com/services/xmlrpc/", false
     
     xmlHttp.send xmlDoc
     dim flickrResponse, photoset, node
     
     dim xmlstr
     xmlstr = replace(replace(xmlHttp.ResponseXML.xml, "&lt;", "<"),"&gt;",">")

     set xmlDOM = Server.CreateObject("MSXML2.DOMDocument")
     xmlDOM.LoadXML(xmlstr)
     
    for each node in xmlDOM.getElementsByTagName("photo")
         response.write "ID: " & node.getAttribute("id") & "<BR>"
         response.write "secret: " & node.getAttribute("secret") & "<BR>"
         response.write "server: " & node.getAttribute("server") & "<BR>"
         response.write "title: " & node.getAttribute("title") & "<BR>"
         response.write "isprimary: " & node.getAttribute("isprimary") & "<BR>"
     next

     response.Write("<br><br>Page End")
     
     'Cleanup XML
     Set xmlHttp = nothing
     Set xmlDOM = Nothing
     
%>
0
 

Author Comment

by:alex_wareing
ID: 16973042
Thanks for all you help
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

635 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