Displaying XML Results from API

Locked
DroBuddy
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Sat Oct 13, 2007 8:22 pm
Location: Varna, IL
Contact:

Displaying XML Results from API

Post by DroBuddy » Mon Jul 21, 2008 9:01 pm

Hello everyone,

I'm still new to the developer aspect and have a few (basic?) questions:

When the user submits a query to the API, the request must be stored in a var and appended to the requested URL, correct? (*NOTE: I've since realized that I don't have to use JS to do this; hence this question is null).

When the client-side receives the response, the JS must define how to handle the returned XML data in order to display it properly? When I start to use innerHTML, this is where I would specify the <div> to display the returned results?

Unfortunately, I put the cart in front of the horse and jumped into AJAX without doing my prep work... And, now I'm a little confused. :-[

In order to get this going, I am not trying to make the following script AJAX-enabled; I'm simply trying to submit the query to the API and display the styled response... So, if someone could offer up some insight, I'd greatly appreciate it.

The form's code is as follows:

Code: Select all

 <FORM METHOD="GET" 
ACTION="http://api.indeed.com/ads/apisearch?publisher=4200000000000">
<TABLE WIDTH=468 HEIGHT=120 border=0 cellpadding=0 cellspacing=0>
  <TR><TD colspan=3 height=15></TR>
  <TR>
        <TD width=155> </TD>
      <TD>       
          <FONT FACE="Arial, Helvetica" SIZE="1" COLOR="black">
        <B>Keywords</B>
        </FONT>
      </TD>
      <TD>
         <FONT FACE="Arial, Helvetica" SIZE="1" COLOR="black">
         <B>Location</B>
        </FONT>
      </TD>
  </TR>
  <TR>
        <TD> </TD>
      <TD><INPUT TYPE="TEXT" name="Keyword" size="18" maxlength="100" 
value=""></TD>
      <TD>
            <SELECT name=RegionList>
            <option value="" selected>[ Select all ] </option>
            <option value=1>Alabama</option>
            <option value=14>Alaska</option>
            <option value=16>Arizona</option>
            <option value=15>Arkansas</option>
            <option value=17>California</option>
            <option value=18>Colorado</option>
            <option value=19>Connecticut</option>
            <option value=21>Delaware</option>
            <option value=20>District Of Columbia</option>
            <option value=22>Florida</option>
            <option value=23>Georgia</option>
            <option value=24>Hawaii</option>
            <option value=26>Idaho</option>
            <option value=27>Illinois</option>
            <option value=28>Indiana</option>
            <option value=25>Iowa</option>
            <option value=29>Kansas</option>
            <option value=30>Kentucky</option>
            <option value=31>Louisiana</option>
            <option value=34>Maine</option>
            <option value=33>Maryland</option>
            <option value=32>Massachusetts</option>
            <option value=35>Michigan</option>
            <option value=36>Minnesota</option>
            <option value=38>Mississippi</option>
            <option value=37>Missouri</option>
            <option value=39>Montana</option>
            <option value=42>Nebraska</option>
            <option value=46>Nevada </option>
            <option value=43>New Hampshire</option>
            <option value=44>New Jersey</option>
            <option value=45>New Mexico</option>
            <option value=47>New York</option>
            <option value=40>North Carolina</option>
            <option value=41>North Dakota</option>
            <option value=48>Ohio</option>
            <option value=49>Oklahoma</option>
            <option value=50>Oregon </option>
            <option value=51>Pennsylvania</option>
            <option value=52>Rhode Island</option>
            <option value=53>South Carolina</option>
            <option value=54>South Dakota</option>
            <option value=55>Tennessee</option>
            <option value=56>Texas</option>
            <option value=57>Utah</option>
            <option value=59>Vermont</option>
            <option value=58>Virginia</option>
            <option value=60>Washington</option>
            <option value=62>West Virginia</option>
            <option value=61>Wisconsin</option>
            <option value=63>Wyoming</option>
        </SELECT>
  </TD>
  <TD>
<INPUT TYPE="image" valign=middle SRC="b_go.gif" BORDER=0 
WIDTH=25 HEIGHT=17>
  </TD>
            
  </TR>
<TR><TD height=3></TD></TR> 
</TABLE>
</FORM> 
Is there any easier way to accomplish this using readily available .js libraries or other languages / protocols?

Is this easier than I'm making it out to be..?

Right now, I could care less about the increased server-load from multiple requests; because, none of that matters if the form doesn't display the results properly, and, inherently, making the site useless.

So, I would truly, greatly appreciate any advice that the community may have to offer. On that note, thank you for your time and assistance.


Sincerely,



Joseph Johnson
"Dro Buddy"
Last edited by DroBuddy on Mon Jul 21, 2008 9:45 pm, edited 1 time in total.

DroBuddy
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Sat Oct 13, 2007 8:22 pm
Location: Varna, IL
Contact:

Re: Displaying XML Results from API

Post by DroBuddy » Mon Jul 21, 2008 9:19 pm

Okay, so I edited the html and now instead of receiving ....KEYWORD=my+query and RegionList=region, it is appending the URL and returning the proper search results (I changed KEYWORD to "q=", RegionList to "l=", and location id's from numeric to state specific (ie. from 1 to alabama, 2 to alaska, etc)). That's definitely a good place to start. 8)

So, how do I go about making sure that the XML results will properly be formatted / styled?

DroBuddy
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Sat Oct 13, 2007 8:22 pm
Location: Varna, IL
Contact:

Re: Displaying XML Results from API

Post by DroBuddy » Wed Jul 23, 2008 8:32 pm

As per the W3C, it states:

Code: Select all

External style sheets

Tip: try it in your browser

HTML has a link element to link to external style sheets, but not every XML-based format will have such an element. If there is no suitable element, you can still attach external style sheets by means of the xml-stylesheet processing instruction like this:

<?xml-stylesheet href="my-style.css" type="text/css"?>
... rest of document here...

This processing instruction (PI) must come before the first tag of the document. The type="text/css" is not required, but it helps the browser: if it doesn't support CSS, it knows it won't have to download this file.

Just as with the link element of HTML, there can be multiple xml-stylesheet PIs and they can have attributes to set the type, medium and title.

Here is a larger example. Let's assume we have three style sheets, one that sets the basic display type of each element (inline, block, list-item, etc.) and two different ones that each set colors and margins. The two last ones are each other's alternative, and the reader of the document may choose which one to use. Except when the document is printed, in which case we only want to use the last style.
However, when you receive the response from the API, you are unable to insert a reference to the CSS. I'm presuming that I need to create my own CSS file that will tell J! how to display the XML information that is returned; in other words, I need to create a separate CSS file to specify how <results>, <result>, etc. should be displayed individually.

But, how do I get it so that the CSS file is referenced within the XML response?

Any clues, ideas, suggestions or reference materials...???

I'm getting really close to getting this resolved, but the styling aspect is what is holding me back. Please help!

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7018
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: Displaying XML Results from API

Post by AmyStephen » Fri Jul 25, 2008 1:09 pm

You include the CSS file in your plugin and create the XML in your plugin and can then easily add the reference to any necessary CSS file or class or ID. This is pretty standard Joomla! extension stuff.

Pull apart a few GPL'ed extensions to see. I'll respond a little more here.

Amy


Locked

Return to “Joombie Tools of the Trade”