2 Replies Latest reply on Feb 28, 2012 7:57 AM by Török Attila

    Flash Builder mobile - complex XML reading

    Török Attila

      Hello Developers,

       

       

      Please help me! I'm trying to develop a mobile app, that displays a complex xml file (i'm not a developer, so please be patient... ). Here's the xml file, then I write what I'd like to do:

       

       

      <?xml version="1.0"?>

      <server_status>

      <hosts>

         <host>

            <host_name>server1</host_name>

            <modified_attributes>0</modified_attributes>

            <check_command>check-host-alive</check_command>

            <check_period>24x7</check_period>

            <notification_period>24x7</notification_period>

         </host>

            <host>

            <host_name>server2</host_name>

            <modified_attributes>0</modified_attributes>

            <check_command>check-host-alive</check_command>

            <check_period>24x7</check_period>

            <notification_period>24x7</notification_period>

         </host>

      </hosts>

      <services>

         <service>

            <host_name>server1</host_name>

            <service_description>C:\ Drive Space - Exchange Edge 1</service_description>

            <modified_attributes>0</modified_attributes>

            <check_command>check_nt!USEDDISKSPACE!-l c -w 80 -c 90</check_command>

                </service>

                <service>

            <host_name>server1</host_name>

            <service_description>CPU Load - Exchange Edge 1</service_description>

            <modified_attributes>0</modified_attributes>

            <check_command>check_nt!CPULOAD!-l 5,80,90</check_command>

                </service>

         <service>

            <host_name>server2</host_name>

            <service_description>C:\ Drive Space - Exchange Edge 2</service_description>

            <modified_attributes>0</modified_attributes>

            <check_command>check_nt!USEDDISKSPACE!-l c -w 80 -c 90</check_command>

                </service>

         <service>

            <host_name>server2</host_name>

            <service_description>CPU Load - Exchange Edge 2</service_description>

            <modified_attributes>0</modified_attributes>

            <check_command>check_nt!CPULOAD!-l 5,80,90</check_command>

                </service>

      </services>

      </server_status>

       

       

      As you can see, there's 2 main nodes: hosts & services. On the opening screen of the app I can list the hosts displaying in a list the host nodes with host_name. That's fine. I select one of them and on the new view I show the selected host attributes like <modified_attributes>, <check_period>, etc. What I want is to display on this screen the selected host's services. Under the <services> node there are 4 <service> child node: 2 services for host1 and 2 services for host2. I only want to list those services that are belong to the host I selected on the main view.

       

       

      Please write me the source code of the solution either here or in email (attila.toeroek@gmail.com)

       

       

      Thanks for your help!

        • 1. Re: Flash Builder mobile - complex XML reading
          Jakub Wojciechowski

          Providing that you are using list component for host selection the dataProvider for your view should look like

           

          dataProvider="{serverStatus.services.service.(host_name == list.selectedItem.host_name)}

          • 2. Re: Flash Builder mobile - complex XML reading
            Török Attila Level 1

            Really thanks for your reply, but I don't really know, where and how to put in the code. Here's the mxml:

             

            <?xml version="1.0" encoding="utf-8"?>

            <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

                                xmlns:s="library://ns.adobe.com/flex/spark"

                                xmlns:szolgaltatas="services.szolgaltatas.*"

                                title="DetailsView"

                                viewActivate="getDetails()"

                                >

             

                      <fx:Script>

                                <![CDATA[

             

             

                                          import mx.events.FlexEvent;

             

             

                                          [Bindable] private var ha:String;

                                          [Bindable] private var hb:String;

                                          [Bindable] private var hc:String;

                                          [Bindable] private var hd:String;

             

                                          import valueObjects.Host;

                                          import valueObjects.Service;

             

             

                                          private function getDetails():void

                                          {

             

                                                    var thisItem:Host = data as Host;

             

                                                    ha = thisItem.last_time_up;

                                                    hb = thisItem.last_check;

                                                    hc = thisItem.plugin_output;

                                                    hd = thisItem.host_name;

             

                                          }

             

                                          protected function textArea_creationCompleteHandler(event:FlexEvent):void

                                          {

                                                    getDataResult.token = szolgaltatas.getData();

             

                                          }

             

             

                                ]]>

                      </fx:Script>

                      <fx:Declarations>

                                <s:CallResponder id="getDataResult"/>

                                <szolgaltatas:Szolgaltatas id="szolgaltatas"/> <!-- Szolgaltatas service -> getData(): Service[] -->

             

             

                      </fx:Declarations>

                      <s:Label top="10" left="10" right="10" text="Time Up: {ha}"/>

                      <s:Label top="30" left="10" right="10" text="Last Check: {hb}"/>

                      <s:Label top="50" left="10" right="10" text="Check Result: {hc}"/>

                      <s:Label top="90" left="10" right="10" text="Hostname: {hd}"/>

                      <s:TextArea id="textArea" left="10" right="10" bottom="10" height="50%"

                                                    creationComplete="textArea_creationCompleteHandler(event)"

                      />

             

             

             

            </s:View>

             

            Thank you Jakub!