8 Replies Latest reply on Jan 2, 2007 7:20 PM by awduke

    XML HTTPService Looping

    awduke
      Could anyone assist me on how to use the HTTPService to read a xml file with a complex structure similar to this
      <?xml version="1.0" encoding="utf-8"?>
      <reports>
      <report>
      <reportDate>2006-11-19
      <manager>
      <id>0</id>
      <name>Elizabeth Jones</name>
      <platform>
      <pltfrmName>AAA</pltfrmName>
      <level>T1</level>
      <desc>3G Authorization, Authentication, Accounting, data call set up</desc>
      <host>
      <hostName>atlngaaaa01</hostName>
      <reportStatus>yes</reportStatus>
      <cpu>41</cpu>
      <memory>20</memory>
      <cache>100</cache>
      <disk>27</disk>
      <network>0</network>
      </host>
      <host>
      <hostName>atlnoraaa01</hostName>
      <reportStatus>yes</reportStatus>
      <cpu>38</cpu>
      <memory>22</memory>
      <cache>100</cache>
      <disk>97</disk>
      <network>0</network>
      </host>
      <host>
      <hostName>bufcheaaa01</hostName>
      <reportStatus>yes</reportStatus>
      <cpu>56</cpu>
      <memory>23</memory>
      <cache>100</cache>
      <disk>96</disk>
      <network>0</network>
      </host>
      <host>
      <hostName>chrchaaaa01</hostName>
      <reportStatus>yes</reportStatus>
      <cpu>39</cpu>
      <memory>25</memory>
      <cache>100</cache>
      <disk>93</disk>
      <network>0</network>
      </host>
      <host>
      <hostName>indindaaa01</hostName>
      <reportStatus>yes</reportStatus>
      <cpu>45</cpu>
      <memory>22</memory>
      <cache>100</cache>
      <disk>96</disk>
      <network>0</network>
      </host>
      <host>
      <hostName>kcindaaa01</hostName>
      <reportStatus>yes</reportStatus>
      <cpu>34</cpu>
      <memory>25</memory>
      <cache>100</cache>
      <disk>78</disk>
      <network>0</network>
      </host>
      <host>
      <hostName>lanlanaaa01</hostName>
      <reportStatus>yes</reportStatus>
      <cpu>44</cpu>
      <memory>26</memory>
      <cache>100</cache>
      <disk>95</disk>
      <network>0</network>
      </host>
      <host>
      <hostName>nybranaaa01</hostName>
      <reportStatus>yes</reportStatus>
      <cpu>60</cpu>
      <memory>23</memory>
      <cache>100</cache>
      <disk>96</disk>
      <network>0</network>
      </host>
      <host>
      <hostName>sfstcaaa01</hostName>
      <reportStatus>yes</reportStatus>
      <cpu>45</cpu>
      <memory>26</memory>
      <cache>100</cache>
      <disk>97</disk>
      <network>0</network>
      </host>
      </platform>
      </manager>
      </reportDate>
      </report>
      <report>
      Now, picture this for all managers in my department for the last 30 days; I’m trying to dynamically generate
      a list of array collections, and then accessing those collections.
      the collections are stored in an Object, and reference them in an associative array that will also generate a dashboard (i.e. like the one posted here http://examples.adobe.com/flex2/inproduct/sdk/dashboard/dashboard.html) per manager (node element) displaying all days. Please respond soon. I really need your help and really admire your tutorials posted at www.cflex.net; they’re well commented and actually work!!
      You can email me also at aduke0880@comcast.net for further details.
      Thanks in advance, Merry Christmas and a Happy New Year to you and family!!!
        • 1. Re: XML HTTPService Looping
          ntsiii Level 3
          Ok, I need more detail on what you want to do. Remember, I do not understand you business, so you need to explain your requirements.

          Don't use words like ArrayCollection and associative array. Instead, tell me what you want the user to see and do.

          How does the sample xml you posted relate to the requirements? what is the significance of the ""30 days"? is there a separate node for each day? Or what?

          Tracy
          • 2. Re: XML HTTPService Looping
            awduke Level 1
            The sample xml node (report) posted is 1 day (node reportDate: 2006-11-19) of data for 5 managers, 296 platforms, over 3000 servers for the last month as capacity dashboard of server hardware metrics {cpu. memory, cache hits, disk, and network} per manager node.

            I would like to create dashboard that displays pie chart, line/bar chart with alternate state to view using a DataGrid control that can be exported or viewed as Excel workbook/worksheet and print the data as xml, pdf, text, or sent directly to a printer per host node (displayed in a ComboBox Control default to All Hosts or selected host) metrics based on the platform under the selected manager as Accordion coomponent which also displays the list of platforms in a VBox Layout to show either one platforms per manager {default} or only the selected platform between a date period selected within the last month or add a range (like the next 60 or 90 days ahead for trend analysis and forecasting) using DateChooser or HSlider Control that mimic one another. That's all I can think of for now, but there will b more features included later as become better in development. So, I really need your help. Any assistance or support references (tutorials, video, etc.) will be greatly appreciated as well.
            Thanks in advance.
            Merry Christmas and Happy New Year!!!

            Alfred Duke
            • 3. Re: XML HTTPService Looping
              ntsiii Level 3
              Ok, how far have you gotten? Are you successfully getting yor data file into Flex?

              Using e4x XML as the primary data repository is the best approach. You can then apply the powerful e4x selection expressions to the complex xml in order to return the node (XML) or nodelist (XMLList) that you want, and you can wrap XMLList in an XMLListCollection, suitable for use as a dataProvider.

              Tracy
              • 4. XML HTTPService Looping
                awduke Level 1
                I'm still trying to load the external xml file into Flex Builder 2 using HTTPService.
                • 5. Re: XML HTTPService Looping
                  ntsiii Level 3
                  Here are some sample code snippets:
                  [Bindable]private var myURL:String = "myFolder/myFile.xml";
                  <mx:HTTPService id="myDS" url="{myUrl}" result="onResult(event)" resultFormat="e4x" />

                  private function onResult(oEvent:ResultEvent):void
                  {
                  var xmlData:XML = XML(oEvent.result );
                  trace(xmlData.toXMLString());
                  }//onREsult

                  Tracy
                  • 6. Re: XML HTTPService Looping
                    awduke Level 1
                    I'm still having a problem to bind a comple xml structure using HTTPService into Flex components. I tried the XMLListCollection and ArrayCollection approach but it was unsuccessful!! Please help me!!

                    Thanks in advance!!
                    • 7. Re: XML HTTPService Looping
                      ntsiii Level 3
                      Again, then, how far have you gotten? Are you successfully getting your data file into Flex?

                      Forget binding for now, can you get your data?

                      Post some code.

                      Tracy
                      • 8. Re: XML HTTPService Looping
                        awduke Level 1
                        <?xml version="1.0" encoding="utf-8"?>
                        <mx:Application
                        xmlns:mx=" http://www.adobe.com/2006/mxml"
                        viewSourceURL="src/DataProviderExternal/index.html"

                        width="350" height="220"
                        creationComplete="bs.send();"
                        >
                        <mx:Script>

                        <![CDATA[
                        import mx.managers.CursorManager;
                        import mx.rpc.events.InvokeEvent;
                        import mx.controls.Alert;
                        import mx.rpc.events.FaultEvent;
                        import mx.rpc.events.ResultEvent;
                        import mx.collections.ArrayCollection;

                        [Bindable]

                        private var bloggersCol:ArrayCollection;

                        // Gets called when HTTPService is invoked to
                        // request the XML.
                        private function bsInvokeHandler(event:InvokeEvent):void

                        {
                        // Display the busy cursor
                        CursorManager.setBusyCursor();
                        }

                        // Gets called when the XML is successfully loaded.
                        private function bsResultHandler(event:ResultEvent):void

                        {
                        // Save a reference to the list of bloggers
                        bloggersCol = event.result.bloggers.blogger;

                        // Hide the busy cursor
                        CursorManager.removeBusyCursor();
                        }


                        private function bsFaultHandler(event:FaultEvent):void
                        {

                        // There was an error in loading the XML
                        Alert.show (event.fault.message);

                        // Hide the busy cursor
                        CursorManager.removeBusyCursor();
                        }
                        ]]>

                        </mx:Script>

                        <!-- Service to load in XML -->
                        <mx:HTTPService
                        id="bs"
                        url="data/bloggers.xml"

                        invoke="bsInvokeHandler(event);"
                        result="bsResultHandler(event);"
                        fault="bsFaultHandler(event);"

                        />
                        It only loops through the base level node and children but not the nodes under the children with children and so forth nested within like such:
                        <managers>
                        <manager name="Elizabeth Jones" title="Capacity Manager">
                        <platform desc="3G Authorization, Authentication, Accounting, data call set up" tier="T1">AAA
                        <host>
                        <hostName>atlngaaaa01</hostName>
                        <currentStateReported>2006-12-18</currentStateReported>
                        <cpu>41</cpu>
                        <memory>20</memory>
                        <cache>100</cache>
                        <disk>27</disk>
                        <network>0</network>
                        </host>
                        <host>
                        ...
                        ...
                        ...
                        </managers>