Ajax + XML + MySQL

Discussion in 'Javascript' started by bcochofel, Dec 13, 2006.

  1. bcochofel

    bcochofel Guest

    Hi, I'm using Perl CGI and HTML::Template to generate the following
    XML:
    ----------------------------------------------------------------------
    <?xml version="1.0" encoding="iso-8859-1"?>
    <?xml-stylesheet type="text/xml" href="RR.xsl"?>
    <!-- $Id: template.xml,v 1.5 2006/12/11 11:13:30 bcochofel Exp $ -->
    <RR
    xmlns:xsi="http://www.w3.org/2001/XMLSchema"
    xsi:schemaLocation="http://cochofel.sytes.net
    ~bcochofel/iweb/files/RR.xsd">
    <Request>
    <url>/~bcochofel/iweb/cgi-bin/getmysites.cgi</url>
    <session>
    <user></user>
    </session>
    <query>
    <!-- o campo parametro pode ter varias ocurrencias -->
    <param name="sort" value="asc" />
    <param name="field" value="" />
    </query>
    </Request>
    <Response>
    <sites>
    <site url="http://www.google.com">
    <tag name="pesquisa" weight="30" />
    <tag name="procura" weight="30" />
    </site>
    <site url="http://www.google.com/webhp?complete=1">
    <tag name="ajax" weight="25" />
    <tag name="pesquisa" weight="30" />
    <tag name="procura" weight="30" />
    </site>
    <site url="https://webmail.fe.up.pt">
    <tag name="email" weight="20" />
    <tag name="feup" weight="20" />
    </site>
    </sites>
    </Response>
    </RR>
    --------------------------------------------------------------
    The Response element gets information from a MySQL DB and this is only
    an example.

    I'm creating a XSL file to transform this XML output in XHTML with the
    results in a table, something like:

    ----------------------
    | URL | TAG | WEIGHT |
    ----------------------

    One URL can have several TAGS. URL is an attribute of the element
    site.

    What I want his to let the client click on the table tittle (url, tag
    or weight) to sort the elements using that field, if the elements are
    already sorted with that field then the order is toogle (ascending
    and descending).

    I want to do this in the client side using Ajax but I can't figure out
    how to do this. How can I get the XML elements without querying the
    MySQL server again? Can I do this? Does javascript has some object to
    retrieve XML elements like this?

    I'm using CGI::Ajax, a Perl module, but if I use this I'll have to
    querie MySQL server again to resort the elements (at least I think I
    have to...)

    Can someone point me out some kind of solution to this? I'm a newbie
    in using Ajax and XML.

    Thanks,
    Bruno
     
    bcochofel, Dec 13, 2006
    #1
    1. Advertising

  2. bcochofel

    bcochofel Guest

    Ok, I know I can use DOM to access the XML elements and attributes
    (with var x=xmlDoc.getElementsByTagName("sites");)

    I want to sort <site> by url, tag/weight (inside the <site>) using
    Ajax.
    How can I sort by tag name attribute or tag weight attr, childs of
    <site>?
    Can I sort my x var like this or do I have to do some kind of
    manipulation?

    I'm thinking of calling a function (inside an href on the table <th>
    elements) an pass a parameter to tell witch <th> was clicked, using
    onClick event. I need to toggle the sorting method if the same <th> has
    clicked, changing from ascending to descending...

    Can I use this?

    bcochofel wrote:

    > Hi, I'm using Perl CGI and HTML::Template to generate the following
    > XML:
    > ----------------------------------------------------------------------
    > <?xml version="1.0" encoding="iso-8859-1"?>
    > <?xml-stylesheet type="text/xml" href="RR.xsl"?>
    > <!-- $Id: template.xml,v 1.5 2006/12/11 11:13:30 bcochofel Exp $ -->
    > <RR
    > xmlns:xsi="http://www.w3.org/2001/XMLSchema"
    > xsi:schemaLocation="http://cochofel.sytes.net
    > ~bcochofel/iweb/files/RR.xsd">
    > <Request>
    > <url>/~bcochofel/iweb/cgi-bin/getmysites.cgi</url>
    > <session>
    > <user></user>
    > </session>
    > <query>
    > <!-- o campo parametro pode ter varias ocurrencias -->
    > <param name="sort" value="asc" />
    > <param name="field" value="" />
    > </query>
    > </Request>
    > <Response>
    > <sites>
    > <site url="http://www.google.com">
    > <tag name="pesquisa" weight="30" />
    > <tag name="procura" weight="30" />
    > </site>
    > <site url="http://www.google.com/webhp?complete=1">
    > <tag name="ajax" weight="25" />
    > <tag name="pesquisa" weight="30" />
    > <tag name="procura" weight="30" />
    > </site>
    > <site url="https://webmail.fe.up.pt">
    > <tag name="email" weight="20" />
    > <tag name="feup" weight="20" />
    > </site>
    > </sites>
    > </Response>
    > </RR>
    > --------------------------------------------------------------
    > The Response element gets information from a MySQL DB and this is only
    > an example.
    >
    > I'm creating a XSL file to transform this XML output in XHTML with the
    > results in a table, something like:
    >
    > ----------------------
    > | URL | TAG | WEIGHT |
    > ----------------------
    >
    > One URL can have several TAGS. URL is an attribute of the element
    > site.
    >
    > What I want his to let the client click on the table tittle (url, tag
    > or weight) to sort the elements using that field, if the elements are
    > already sorted with that field then the order is toogle (ascending
    > and descending).
    >
    > I want to do this in the client side using Ajax but I can't figure out
    > how to do this. How can I get the XML elements without querying the
    > MySQL server again? Can I do this? Does javascript has some object to
    > retrieve XML elements like this?
    >
    > I'm using CGI::Ajax, a Perl module, but if I use this I'll have to
    > querie MySQL server again to resort the elements (at least I think I
    > have to...)
    >
    > Can someone point me out some kind of solution to this? I'm a newbie
    > in using Ajax and XML.
    >
    > Thanks,
    > Bruno
     
    bcochofel, Dec 15, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JL
    Replies:
    0
    Views:
    1,179
  2. Ravi
    Replies:
    6
    Views:
    1,445
    Suchandra Thapa
    Jul 21, 2003
  3. Replies:
    2
    Views:
    6,254
  4. minnie
    Replies:
    1
    Views:
    770
    Andrew Thompson
    Dec 13, 2006
  5. bcochofel

    Ajax + XML + MySQL

    bcochofel, Dec 13, 2006, in forum: XML
    Replies:
    1
    Views:
    441
Loading...

Share This Page