Solved

XML and ASP

Posted on 2006-06-21
4
474 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for all you help
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

16 Experts available now in Live!

Get 1:1 Help Now