...

View Full Version : Help Using an API



FoGo
11-20-2012, 02:11 AM
Essentially, I need help understanding how to use this (http://boardgamegeek.com/wiki/page/BGG_XML_API&redirectedfrom=XML_API#) 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 (http://www.boardgamegeek.com/xmlapi/boardgame/35424,2860) 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.

Logic Ali
11-20-2012, 05:55 AM
when a board game is searched for, it returns an XML document that looks like this (http://www.boardgamegeek.com/xmlapi/boardgame/35424,2860) 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.

Old Pedant
11-20-2012, 07:09 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum