4 Replies Latest reply on Jun 5, 2013 4:24 AM by AMULI

    Loading multiple data from a XML file?

    Rafael Carignato

      Hi,

       

      I'm having trouble loading multiple data from the same XML file. In this XML file I have a list of dishes I want to add into a menu. So, how can I load multiple data from different branches of the XML file into my text fields?

       

      Thanks in advance,

      Rafael Carignato

        • 1. Re: Loading multiple data from a XML file?
          shadowfax007 Level 1

          I'm not quite sure what you are trying to do.  I have this working with a .JSON file that loads "multiple" date into "multiple" fields in Edge - Is that what you mean?

           

          Here's an example:

           

          $.getJSON('slides.json', function(data) {

           

                    for(var i=0;  i<data.length;  i++)

                    {

                                        var s = sym.createChildSymbol("slide", "stage");

                                        s.$("photo").css({"background-image":"url('"+data[i].image+"')"});

                                        s.$("title").html(data[i].title);

                                        s.$("price").html(data[i].price);

                                        s.getSymbolElement().css({"position":"absolute",

                                                            "left": i*225+50+"px",

                                                            "top":"100px"});

                    }

          });

           

          Each name above (photo, title, price) has an element on the stage (or in my case, a symbol) and my .JSON file has has a "branch" for each of these:

           

          [{

          "image" : "images/7783.jpg",

          "title" : "SNOCONUTS",

          "price" : "12.00"

          }

          ]

          ...

           

          Hope that helps...

           

          James

          1 person found this helpful
          • 2. Re: Loading multiple data from a XML file?
            AMULI Level 4

            Thank you James,

             

            I was planning to make a generic slideshow from XML data. This is well-timed and very helpful.

             

            Having an AS3 background, I was wondering about asynchronous programming. This getJSON method looks like the equivalent of an Event.COMPLETE event handler.

             

            What about the equivalent of an IOErrorEvent.IO_ERROR event handler ? Thanks,

             

            Gil

            • 3. Re: Loading multiple data from a XML file?
              Rafael Carignato Level 1

              Found a way to do it. I created X text elements named "textbox1", "textbox2", etc. Here's the code:

               

              var i = 1;

              var message;

               

               

                      $.ajax({

                              type: "GET",

                              url: "books.xml",

                              dataType: "xml",

                              success: function (xml) {

                                  $(xml).find('Book').each(function () {

                                      var sTitle = $(this).find('Title').text();

                                      var sAuthor = $(this).find('Author').text();

                                      var sGenre = $(this).find('Genre').text();

                                      message = sTitle + ", " + sAuthor + ", " + sGenre;

                                      console.log("Message: " + message);

                                      console.log("i :" + i);

                                      sym.$("textbox" + i).html(message);

                                      console.log("");

                                      i++;

                                });

                              },

                          });

              • 4. Re: Loading multiple data from a XML file?
                AMULI Level 4

                Thank you Rafael,

                 

                Being much more comfortable with XML, I will follow your example for the slideshow.

                 

                I just bought the book Learning jQuery (Packt Pub). Skimming through, I saw code similar to yours in chapter 6 (Sending Data with Ajax). After reading it, I will possibly complete the thread about error handling.

                 

                Gil