Solved

XML and ASP

Posted on 2006-06-21
4
479 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
  • 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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