6 Replies Latest reply on Aug 11, 2009 8:12 PM by kglad

    cannot parse data from xml

    alexManuelSilva

      I am trying to obtain strings from a xml file:

       

      I tried the following:

       

      var url:URLRequest = new URLRequest("blog.xml");

      var xml:XML;
      var rss:URLLoader = new URLLoader();
      rss.load(url);
      rss.addEventListener(Event.COMPLETE, readRss);

      function readRss(e:Event):void{
             xml = XML(rss.data);
             txt_field.text=xml.entry[1].author.name;

      }

       

      but had no results. TypeError: Error #1010:...

      I tried tracing xml and that worked fine.

      The xml structure seems to be too complex

       

      var blogList:XMLList = xml.children(); //returns a more simple xml structure but still no success in parsing parts of the xml such as "title" or "author".

      Any suggestions would be greatly appreciated.

      Thanks

        • 1. Re: cannot parse data from xml
          kglad Adobe Community Professional & MVP

          you have to use that namespace.

          • 2. Re: cannot parse data from xml
            kglad Adobe Community Professional & MVP

             

            var url:URLRequest = new URLRequest("blog.xml");

            var xml:XML;
            var rss:URLLoader = new URLLoader();
            rss.load(url);
            rss.addEventListener(Event.COMPLETE, readRss);

            function readRss(e:Event):void{
                   xml = XML(rss.data);

            var ns:Namespace=xml.namespace();
                   txt_field.text=xml..ns::name[0];

            }

             


            • 3. Re: cannot parse data from xml
              alexManuelSilva Level 1

              Hi Kglad,

              thank you for helping me with this post and all the previous threads.

               

               

               

              for accessing entry[1].title, i tried:

               

              xml..ns::entry[0].title // but didn´t really work.

               

               

              I also tried to retrieve all the items under "entry" with:

               

                 var ns:Namespace=xmlData.namespace();
                 var MSGCounter:int = 1;

               

                 for each (var item:XML in xmlData..ns)
                 {
                  txt_field.appendText("Post "+MSGCounter++ +"\n")
                  txt_field.appendText("------------------------------------------------------------------- -----\n");
                  txt_field.appendText(item.entry.title.toString());
                  txt_field.appendText("\n");
                  txt_field.appendText("\n");
                  txt_field.appendText(item.entry.content.toString());
                  txt_field.appendText("\n ");
                  txt_field.appendText("\n ");
                  txt_field.appendText(item.entry.author.name.toString());
                  txt_field.appendText("\n\n");
                 }


              but had no success.

              • 4. Re: cannot parse data from xml
                kglad Adobe Community Professional & MVP

                try:

                 

                xml..ns::entry[0].ns::title;  // for entry[0] title

                 

                xml..ns::entry[1].ns::title;  // for entry[1] title

                1 person found this helpful
                • 5. Re: cannot parse data from xml
                  alexManuelSilva Level 1

                  Thanks, kglad.

                   

                  I added:

                     var ln:int = 5;
                     for(var i:int; i < ln; i++) {
                      txt_field.appendText("Post "+MSGCounter++ +"\n")
                      txt_field.appendText("------------------------------------------------------------------- -----\n");
                      txt_field.appendText("\n");
                      txt_field.appendText(xmlData..ns::entry[i].ns::title);
                      txt_field.appendText("\n ");
                      txt_field.appendText("\n ");
                      txt_field.appendText(xmlData..ns::entry[i].ns::content);
                      txt_field.appendText("\n ");
                      txt_field.appendText("\n ");
                     }

                  • 6. Re: cannot parse data from xml
                    kglad Adobe Community Professional & MVP

                    you're welcome.