Solved

XML and ASP

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Classic ASP migration directions 7 66
Css expand Div to fit its content (Of other divs) 4 46
Forcing form refresh - classic ASP 7 57
Summernote required 3 98
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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/…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
A short film showing how OnPage and Connectwise integration works.

929 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now