Solved

XML and ASP

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
If-Then-Else ASP problem 6 67
Pass asp session variable to a js function in an asp script 6 27
ASP server side get value 15 35
Asp in script 6 39
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/…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
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…

828 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