3 Replies Latest reply on Dec 18, 2007 2:50 PM by

    How to reference/read an XML file?

      Instead of inline XML content, pls see code below, thanks.

      <?xml version="1.0"?>
      <!-- dpcontrols/DataGridSimple.mxml -->
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
      <!--
      <mx:XMLList id="employees">
      <employee>
      <name>Christina Coenraets</name>
      <phone>555-219-2270</phone>
      <email>ccoenraets@fictitious.com</email>
      <active>true</active>
      <notes>
      Christina is a hot chic.
      </notes>
      </employee>
      <employee>
      <name>Joanne Wall</name>
      <phone>555-219-2012</phone>
      <email>jwall@fictitious.com</email>
      <active>true</active>
      <notes>
      What a b!
      </notes>
      </employee>
      <employee>
      <name>Maurice Smith</name>
      <phone>555-219-2012</phone>
      <email>maurice@fictitious.com</email>
      <active>false</active>
      <notes>
      Just a pimp.
      </notes>
      </employee>
      <employee>
      <name>Mary Jones</name>
      <phone>555-219-2000</phone>
      <email>mjones@fictitious.com</email>
      <active>true</active>
      <notes>
      Mary, Mary, Mary
      </notes>
      </employee>
      </mx:XMLList>
      -->
      <mx:Panel title="DataGrid Control Example" height="100%" width="100%"
      paddingTop="10" paddingLeft="10" paddingRight="10">

      <mx:Label width="100%" color="blue"
      text="Select a row in the DataGrid control."/>

      <!-- previous inline reference, dataProvider={employees} -->
      <mx:DataGrid id="dg" width="100%" height="100%" rowCount="5" dataProvider="{C:\ColdFusion8\wwwroot\Flex\employees.xml}">
      <!-- the above dataProvider reference won't work, how? -->
      <mx:columns>
      <mx:DataGridColumn dataField="name" headerText="Name"/>
      <mx:DataGridColumn dataField="phone" headerText="Phone"/>
      <mx:DataGridColumn dataField="email" headerText="Email"/>
      </mx:columns>
      </mx:DataGrid>

      <mx:Form width="100%" height="100%">
      <mx:FormItem label="Name">
      <mx:Label text="{dg.selectedItem.name}"/>
      </mx:FormItem>
      <mx:FormItem label="Email">
      <mx:Label text="{dg.selectedItem.email}"/>
      </mx:FormItem>
      <mx:FormItem label="Phone">
      <mx:Label text="{dg.selectedItem.phone}"/>
      </mx:FormItem>
      <mx:FormItem label="Notes">
      <mx:Label text="{dg.selectedItem.notes}"/>
      </mx:FormItem>
      </mx:Form>

      </mx:Panel>

      </mx:Application>
        • 1. Re: How to reference/read an XML file?
          MonsonHaefel
          the dataProvider attribute in DataGrid does not point to a file. It uses (i think) E4X to define a path from a data provider (i.e. HTTPService). You need to access the XML file using an data provider first and then use that reference to access element data in the document via the dataProvider.

          Hope that helps a little.
          • 2. Re: How to reference/read an XML file?
            Gregory Lafrance Level 6
            I finally got this to work. You need to use an HTTPService component. Here is a good FB help topic (some of the other on this topic don't seem to work):
            Populate a DataGrid control

            Here is the XML file:
            ------------------------- xml/SimpleDatagrid.xml -----------------------------
            <?xml version="1.0" encoding="utf-8"?>
            <employees>
            <employee>
            <name>Christina Coenraets</name>
            <phone>555-219-2270</phone>
            <email>ccoenraets@fictitious.com</email>
            <active>true</active>
            <notes>Christina is in the accounting dept.</notes>
            </employee>
            <employee>
            <name>Joanne Wall</name>
            <phone>555-219-2012</phone>
            <email>jwall@fictitious.com</email>
            <active>true</active>
            <notes>Joanne is in the finance dept.</notes>
            </employee>
            <employee>
            <name>Maurice Smith</name>
            <phone>555-219-2012</phone>
            <email>maurice@fictitious.com</email>
            <active>false</active>
            <notes>Maurice is in the finance dept.</notes>
            </employee>
            <employee>
            <name>Mary Jones</name>
            <phone>555-219-2000</phone>
            <email>mjones@fictitious.com</email>
            <active>true</active>
            <notes>Mary is in the marketing dept.</notes>
            </employee>
            </employees>
            ---------------------------- Test.mxml --------------------------------
            <?xml version="1.0"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="srv.send()">
            <mx:HTTPService id="srv" url="xml/SimpleDatagrid.xml" useProxy="false"/>

            <mx:Panel title="DataGrid Control Example" height="100%" width="100%">
            <mx:Label width="100%" color="blue" text="Select a row in the DataGrid control."/>

            <mx:DataGrid id="dg" width="100%" height="100%" rowCount="5"
            dataProvider="{srv.lastResult.employees.employee}">
            <mx:columns>
            <mx:DataGridColumn dataField="name" headerText="Name"/>
            <mx:DataGridColumn dataField="phone" headerText="Phone"/>
            <mx:DataGridColumn dataField="email" headerText="Email"/>
            <mx:DataGridColumn dataField="active" headerText="Active"/>
            <mx:DataGridColumn dataField="notes" headerText="Notes"/>
            </mx:columns>
            </mx:DataGrid>

            <mx:Form width="100%" height="100%">
            <mx:FormItem label="Name">
            <mx:Label text="{dg.selectedItem.name}"/>
            </mx:FormItem>
            <mx:FormItem label="Email">
            <mx:Label text="{dg.selectedItem.email}"/>
            </mx:FormItem>
            <mx:FormItem label="Phone">
            <mx:Label text="{dg.selectedItem.phone}"/>
            </mx:FormItem>
            <mx:FormItem label="Active">
            <mx:Label text="{dg.selectedItem.active}"/>
            </mx:FormItem>
            <mx:FormItem label="Notes">
            <mx:Label text="{dg.selectedItem.notes}"/>
            </mx:FormItem>
            </mx:Form>
            </mx:Panel>
            </mx:Application>
            1 person found this helpful
            • 3. Re: How to reference/read an XML file?
              that's cool!
              My first try was successful, then I tried to add some special character, that is, a sinlge quote, like {Mary's Husband} as value for a new row's "Notes" field, it bombed, err msg like [RPC Fault faultString="HTTP request error"

              I won't sweat on this, but you got it going good...