5 Replies Latest reply on Apr 17, 2010 8:15 AM by icecappacino

    Loading XML with namespaces

    icecappacino Level 1

      Hey guys,


      I'm triyng to load an xml feed which has namespaces in it but for some reason in trying to debug the code im not able to access the document tree for it



      the xml feed can be found here


      I am able to x.toString(); and get the result output but thats it...for some reason variables l and data are empty.

        • 1. Re: Loading XML with namespaces
          Flex harUI Adobe Employee

          The link was a web page.  Copy and paste the tags and the xmlns tags

          • 2. Re: Loading XML with namespaces
            Peter deHaan Level 4

            Look into the "default xml namespace": http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/statements.html#default _xml_namespace


            This is a bit rough, but may help get you started:


            <?xml version="1.0" encoding="utf-8"?>
            <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                        import mx.collections.XMLListCollection;
                        import mx.controls.Alert;
                        import mx.rpc.events.FaultEvent;
                        import mx.rpc.events.ResultEvent;
                        import spark.events.IndexChangeEvent;
                        default xml namespace = "http://www.w3.org/2005/Atom";
                        private var theXML:XML;
                        protected function httpServ_faultHandler(evt:FaultEvent):void {
                        protected function httpServ_resultHandler(evt:ResultEvent):void {
                            theXML = httpServ.lastResult as XML;
                            list.dataProvider = new XMLListCollection(theXML.entry);
                        protected function list_labelFunc(item:XML):String {
                            return item.title.text();
                        protected function list_changeHandler(evt:IndexChangeEvent):void {
                            if (list.selectedItem) {
                                auth.text = "Author: " + list.selectedItem.author.name.text();
                            } else {
                                auth.text = "";
                    <s:HTTPService id="httpServ"
                                   result="httpServ_resultHandler(event);" />
                <s:HGroup x="20" y="20">
                    <s:List id="list"
                            <s:VerticalLayout gap="0" horizontalAlign="contentJustify" requestedRowCount="5" />
                    <s:Label id="auth" />



            • 3. Re: Loading XML with namespaces
              icecappacino Level 1

              Hi...i tried to resolve the issue based on your explanation but I don't think I got it...


              I have in the httpservice result handler


              default xml namespace = 'http://www.w3.org/2005/Atom';
                                  var x:XML = event.result as XML;
                                  var data = new XMLListCollection(x.entry);
                                  var S = data[0].title.text();
                                  galleriesListDG.dataProvider = data;

              In debugging I get the expected result string. However the list doesn't seem to have any of the vaules



              The above is in an  mx:itemRenderer. I also note that I'm getting a


              warning: unable to bind to property 'title' on class 'XML' (class is not an IEventDispatcher)

              I'm not sure what that means though...note that I'm note using Flex as my development tool

              • 4. Re: Loading XML with namespaces
                icecappacino Level 1

                This is as far as I have gotten

                private function listGalleries(event:ResultEvent) {
                                    default xml namespace = "http://www.triniscene.com/mynamespace";
                                    var x:XML = new XML(event.result);
                                    //x.addNamespace(new Namespace('ts',));
                                    var data = x.entry.title.text();
                                    //var S = data[0].title;
                                    //galleriesListDG.dataProvider = data;
                                    var d= 1;
                                    var e = 2;

                a x.toXMLString() gives me an output but x.entry.title doesn't. Maybe it can't handle the specific namespaces....is there like a list of namespaces that it does/ doesn't support. I think as an upgrade they should consider carefully thier XML features. seems to be lacking here i think.

                • 5. Re: Loading XML with namespaces
                  icecappacino Level 1

                  Further to my findings I realize that the xml structure is being altered in the XML object in Flex.

                  In the markup


                  namespace xmlns = "http://www.w3.org/2005/Atom";
                          use namespace xmlns;
                          namespace ts = 'http://www.triniscene.com/namspace';
                          use namespace ts;
                          private function listGalleries(event:ResultEvent) {
                                      var t:XML = event.result as XML;
                                      t.ignoreWhiteSpace = true;
                                      t.prettyIndent = true;
                                      var m = (t.child(6).name());
                                      //galleriesListDG.dataProvider = t.channel.item;
                                      var d = 1;

                  t.toXMLString() will give me the xml structure intact!.

                  t.namespace gives me the "http://www.w3.org/2005/Atom" what gets strange is when i get the name of the elements. the element t.child(6).name() give me "http://www.w3.org/2005/Atom:entry" instead of "entry". In debugging every element has been retagged with a namespace = "http://www.w3.org/2005/Atom".


                  I know I can get around it by simple t.*::entry but why is it doing this?


                  check the atom feed is here