Loading ...
Sorry, an error occurred while loading the content.
 

Problem with XML Data

Expand Messages
  • manhtuanquan78
    Hi. Everybody, I have problem with XML Data . It is a first time i use Yahoo UI so I don t understand how to use XML Data (in Datatable example ) Please see
    Message 1 of 3 , Dec 19, 2007
      Hi. Everybody, I have problem with XML Data . It is a first time i use
      Yahoo UI so I don't understand how to use XML Data (in Datatable example )

      Please see Javascrip below: (code in example)

      <script type="text/javascript">
      YAHOO.util.Event.addListener(window, "load", function() {
      YAHOO.example.Local_XML = new function() {
      this.connectionCallback = {
      success: function(o) {
      var xmlDoc = o.responseXML;

      var myColumnDefs = [
      {key:"Title", label:"Name", sortable:true,
      formatter:this.formatUrl},
      {key:"Phone"},
      {key:"City"},
      {key:"AverageRating",
      label:"Rating",formatter:YAHOO.widget.DataTable.formatNumber,
      sortable:true}
      ];

      this.myDataSource = new YAHOO.util.DataSource(xmlDoc);
      this.myDataSource.responseType =
      YAHOO.util.DataSource.TYPE_XML;
      this.myDataSource.responseSchema = {
      resultNode: "Result",
      fields:
      ["Title","Phone","City",{key:"AverageRating",parser:YAHOO.util.DataSource.parseNumber},"ClickUrl"]
      };

      this.myDataTable = new
      YAHOO.widget.DataTable("localxml", myColumnDefs, this.myDataSource);

      },
      failure: function(o) {

      }
      };

      this.getXML = YAHOO.util.Connect.asyncRequest("GET",

      "assets/php/ylocal_proxy.php?query=pizza&zip=94089&results=10",
      this.connectionCallback);
      };
      });
      </script>

      I dont understand about: xmlDoc , o.responseXML.
      Where I can get DataSource? I have a xml file but I dont know where i
      need to put? How to get data from XML file???

      (I downloaded example but No records found in run time).
      Please help me for details. Thank you!!!
    • Satyam
      You don t need to use the Connection Manager yourself, the DataSource can take care of that. You would break the URL into the base part and the arguments. The
      Message 2 of 3 , Dec 19, 2007
        You don't need to use the Connection Manager yourself, the DataSource can
        take care of that. You would break the URL into the base part and the
        arguments. The base up to and including the ? sign, you use as the argument
        to the new DataSource. The argument part you put into the fourth, optional,
        argument of the DataTable constructor as configuration property
        initialRequest.

        There is nothing wrong with doing it your way, specially if you needed some
        information from the XML data before allowing it to reach the DataSource but
        since that doesn't seem to be the case, it is not worth the trouble.

        Your DataTable might be empty because your page cannot reach the server with
        the relative URL you provided. That is a matter of how you have your server
        set up or fixing the URL. You probably can't tell because you have your
        failure callback function empty but if you were to call alert with the
        status information from the failure callback, I'm quite sure you would get a
        404 Page not found error.

        If you want to work locally with the examples, your best solution is to
        download the whole YUI library, unzip it in a directory in your web server,
        make sure your web server can interpret PHP scripts and run the examples
        from the examples folder in your copy of YUI, in that way, all the relative
        URLs will work. Do not use file system paths to the scripts, use
        http://localhost/... so everything goes through the web server and, in the
        examples such as this that use PHP; through the PHP interpreter. This
        example and all the others that use PHP will not work if you just double
        click on the .html file to open it.

        Satyam



        ----- Original Message -----
        From: "manhtuanquan78" <manhtuanquan78@...>
        To: <ydn-javascript@yahoogroups.com>
        Sent: Thursday, December 20, 2007 2:31 AM
        Subject: [ydn-javascript] Problem with XML Data


        > Hi. Everybody, I have problem with XML Data . It is a first time i use
        > Yahoo UI so I don't understand how to use XML Data (in Datatable example )
        >
        > Please see Javascrip below: (code in example)
        >
        > <script type="text/javascript">
        > YAHOO.util.Event.addListener(window, "load", function() {
        > YAHOO.example.Local_XML = new function() {
        > this.connectionCallback = {
        > success: function(o) {
        > var xmlDoc = o.responseXML;
        >
        > var myColumnDefs = [
        > {key:"Title", label:"Name", sortable:true,
        > formatter:this.formatUrl},
        > {key:"Phone"},
        > {key:"City"},
        > {key:"AverageRating",
        > label:"Rating",formatter:YAHOO.widget.DataTable.formatNumber,
        > sortable:true}
        > ];
        >
        > this.myDataSource = new YAHOO.util.DataSource(xmlDoc);
        > this.myDataSource.responseType =
        > YAHOO.util.DataSource.TYPE_XML;
        > this.myDataSource.responseSchema = {
        > resultNode: "Result",
        > fields:
        > ["Title","Phone","City",{key:"AverageRating",parser:YAHOO.util.DataSource.parseNumber},"ClickUrl"]
        > };
        >
        > this.myDataTable = new
        > YAHOO.widget.DataTable("localxml", myColumnDefs, this.myDataSource);
        >
        > },
        > failure: function(o) {
        >
        > }
        > };
        >
        > this.getXML = YAHOO.util.Connect.asyncRequest("GET",
        >
        > "assets/php/ylocal_proxy.php?query=pizza&zip=94089&results=10",
        > this.connectionCallback);
        > };
        > });
        > </script>
        >
        > I dont understand about: xmlDoc , o.responseXML.
        > Where I can get DataSource? I have a xml file but I dont know where i
        > need to put? How to get data from XML file???
        >
        > (I downloaded example but No records found in run time).
        > Please help me for details. Thank you!!!
        >
        >
        >
        >
        >
        > Yahoo! Groups Links
        >
        >
        >
        >
        >
        > --
        > No virus found in this incoming message.
        > Checked by AVG Free Edition.
        > Version: 7.5.503 / Virus Database: 269.17.4/1189 - Release Date:
        > 18/12/2007 21:40
        >
      • manhtuanquan78
        Thank Satyam! I understand :) ... DataSource can ... argument ... optional, ... needed some ... DataSource but ... server with ... your server ... your ...
        Message 3 of 3 , Jan 2 5:59 PM
          Thank Satyam! I understand :)
          --- In ydn-javascript@yahoogroups.com, "Satyam" <satyam@...> wrote:
          >
          > You don't need to use the Connection Manager yourself, the
          DataSource can
          > take care of that. You would break the URL into the base part and the
          > arguments. The base up to and including the ? sign, you use as the
          argument
          > to the new DataSource. The argument part you put into the fourth,
          optional,
          > argument of the DataTable constructor as configuration property
          > initialRequest.
          >
          > There is nothing wrong with doing it your way, specially if you
          needed some
          > information from the XML data before allowing it to reach the
          DataSource but
          > since that doesn't seem to be the case, it is not worth the trouble.
          >
          > Your DataTable might be empty because your page cannot reach the
          server with
          > the relative URL you provided. That is a matter of how you have
          your server
          > set up or fixing the URL. You probably can't tell because you have
          your
          > failure callback function empty but if you were to call alert with the
          > status information from the failure callback, I'm quite sure you
          would get a
          > 404 Page not found error.
          >
          > If you want to work locally with the examples, your best solution is to
          > download the whole YUI library, unzip it in a directory in your web
          server,
          > make sure your web server can interpret PHP scripts and run the
          examples
          > from the examples folder in your copy of YUI, in that way, all the
          relative
          > URLs will work. Do not use file system paths to the scripts, use
          > http://localhost/... so everything goes through the web server and,
          in the
          > examples such as this that use PHP; through the PHP interpreter. This
          > example and all the others that use PHP will not work if you just
          double
          > click on the .html file to open it.
          >
          > Satyam
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.