Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help Using an API

    Essentially, I need help understanding how to use this api to do exactly as it is intended. I think I can muddle my way through it up to a point but here's what I don't understand: when a board game is searched for, it returns an XML document that looks like this and I need to know how I would access these elements in a way that would allow me to use them on my own site (this is for purely educational purposes and in line with their terms of use).

    I hope this is not too broad a question or in the wrong section. I am taking a class that has flown through a bunch of topics in a way that has left me with a very limited understanding of most of them so I'll be the first to admit that I don't know what I'm doing.

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by FoGo View Post
    when a board game is searched for, it returns an XML document that looks like this and I need to know how I would access these elements in a way that would allow me to use them on my own site
    Where xmlDoc is the returned object:

    var games = xmlDoc.getElementsByTagName( 'boardgame' ); should get you a table of <boardgame> elements.

    Their attributes ( I don't mean their child elements ) won't be readable directly, you must use getAttribute.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,550
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    Ummm...but what is missing here is *HOW* you will get the given XML data to *YOUR* computer.

    JavaScript alone can't do it.

    That's because JavaScript is only allowed to read files (or other source material) from the *SAME DOMAIN* as the HTML page that hosts the JavaScript.

    So normally there are two ways to do this:
    (1) Do it in server-side code. PHP or JSP or ASP or whatever.
    (2) Create a "proxy server" on your own server that gets a request from your own JS code (presumably an AJAX call) and uses the information in that request to simply go to the foreign server, retrieve the XML stream, and send it back to your JS code.

    In either case, you need something server-side to accomplish this.

    There *ARE* sneaky techniques you can use to get XML content like this from a foreign server to your own JavaScript, but they require the cooperation of the foreign server. You could inquire of that service if they support such a scheme.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •