4 Replies Latest reply on Aug 11, 2009 8:39 AM by PeakDigital

    Keep PHP-generated XML as XML?

    PeakDigital Level 1

      I am working on my first Tree component, and wrote PHP script that generates my XML hierarchy using attributes, in the format demonstrated at http://livedocs.adobe.com/flex/3/html/help.html?content=dpcontrols_8.html  (The mailbox example).

       

      The return from the PHP script is handled by the HTTPService's result handler. When I debug it, the event.result shows as an ArrayCollection instead of XML.

       

      If I try to cast it to XMLList like this: var listXML:XMLList=XMLList(event.result.data); the listXML variable contains a single node containing "[object Object]".

       

      Is there any way to preserve my E4X XML data for use in my Tree component, or am I going to have to write code to convert it back to XML?

       

      Thanks.

      Paul

        • 1. Re: Keep PHP-generated XML as XML?
          Gregory Lafrance Level 6

          Ensure your HTTPService resultFormat property is set to e4x.

           

          In the result handler, do this:

           

          var xmllist:XMLList = event.result..myNode as XMLList;

          xlc = new XMLListCollection(xmllist);

           

          where xlc is a global XMLListCollection variable, and myNode is the node in the XML that repeats.

           

          If this post answered your question or helped, please mark it as such.

          1 person found this helpful
          • 2. Re: Keep PHP-generated XML as XML?
            PeakDigital Level 1

            Greg,

             

            Thank you for your reply.

             

            I had missed the resultFormat=4x; however even after fixing that I am running into problems getting the XML into an XMLList using the syntax you suggested. No error occurs, but my XMLList variable shows as null.

             

            My structure is:

            <data>

                 <parentLocation id="1" LocationName="Building 1">

                      <location id="3" LocationName="Room A">

                           <location id="5" LocationName="Cube 1-b"></location>

                           <location id="6" LocationName="Cube 2-C"></location>

                      </location>

                     <location id="10" LocationName="Room B"></location>

                 </parentLocation>             

                 <parentLocation  id="2" LocationName="Building 2">

                      ...etc

                   </parentLocation>

            </data>

             

            In the debugger, I entered several variations of the dot-syntax event result into the expression pane:

            event.result.data = <errors during evaluation>   No such variable: data
            event.result<data> = <errors during evaluation>    Syntax error in expression
            event.result as XMLList = <errors during evaluation>    Expression could not be fully resolved
            event.result["data"]\n = <errors during evaluation>    No such variable: data
            event.result.<data>\n = <errors during evaluation>    Syntax error in expression
            event.result..data = <errors during evaluation>    Syntax error in expression


            event.result.data.parentLocation = <errors during evaluation>    No such variable: data
            event.result..parentLocation = <errors during evaluation>   Syntax error in expression

             

            If I type just "event.result" in the expressions pane, it shows "event.result = (XML) <data>    "

             

            I'll keep hacking away at this as long as I can keep my eyes open, running out of ideas.

            • 3. Re: Keep PHP-generated XML as XML?
              Muzak Level 3

              Since event.result equals <data>etc..</data> you don't use event.result.data to access it, but just event.result.

               

              So to get a list of parentLocation  nodes, use event.result.parentLocation

               

              var data:XML = event.result as XML;
              var locs:XMLList = data.parentLocation;
              trace(locs.toXMLString());
              
              1 person found this helpful
              • 4. Re: Keep PHP-generated XML as XML?
                PeakDigital Level 1

                Thank you!  That works.

                 

                This is the first time I have tried to use XML in this format. I didn't make the connection between the expression pane showing "event.result = (XML) <data>   " to needing to bypass the root node.

                 

                No end of learning new things in Flex, I guess.

                 

                Thank you both for your assistance.

                 

                Paul