Jason,

That was perfect.  Thank you for taking the time to explain the situation.

Best regards,
~David T.
 

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Jason 
Hawryluk
Sent: Friday, March 31, 2006 4:23 PM
To: [email protected]
Subject: RE: [flexcoders] Beyond Confused (Please Help)- Flex 2 Beta 2 - 
HTTPService & XML

Ok on the tree the label field has to be the same name for all nodes, if you 
take a look in the docs for labelField every example has the same field name 
for the tree control.

you need to get your xml output looking like. The tree does not know how to 
properly display arbitrary xml elements.

<Employee label="Lynn Tsoflias" otherinfo1="">
        <SalesTerritory label="Australia" otherinfo1="">
                <SalesPerson label="36" otherinfo1="">
                </SalesPerson>
        </SalesTerritory>
</Employee>

<Employee label="José Saraiva" otherinfo1="">
        <SalesTerritory label="Canada" otherinfo1="">
        <SalesPerson label="31" otherinfo1="">
        </SalesPerson>
        </SalesTerritory>
</Employee>

Use attributes and when the user selects get at the id's with the @label type 
of call to the selected item

so [EMAIL PROTECTED] gives you your info for example.

or i think the tree is better user like this

private function labelFormater(curritem:XML):String{
        return curritem.name();
}

<mx:Tree change="handleChange(event)" width="100%" height="250" id="xmltree"
labelFunction="labelFormater"  dataProvider="{MyDS2}"></mx:Tree>

Then you display the element children in your list

private function handleChange(event:Event):void{
        testtree.dataProvider = event.currentTarget.selectedItem; }

<mx:DataGrid id="testtree" dataProvider="{rawXML.result.ROOT.row}"
height="300" />

Think of the tree as selecting sales people or territory then the grid as 
people in that territory. Or some other variant like that.

Of course that all depends on what you goal is :)

In my tree's I never did it this way i have always used attributes for a tree 
structure. So you have this or a label function but a label function will still 
not give what you want, better off trying to get you format eatable for flex.

It has to be the same value label for each node or a labelfunction.

In the case of the grid you can't as far as I know get at the nested elements 
just using the dataField, it sure as heck would be handy though.

So your going to need to create a itemrenderer action script class. These are 
well documented and you better to get your head around them asap.

extending components and building renderers I find are a big part of developing 
in Flex.

sorry i could not be of more help

jason




-----Message d'origine-----
De : [email protected] [mailto:[EMAIL PROTECTED] la part de David 
Terry Envoyé : vendredi 31 mars 2006 23:17 À : [email protected] Objet 
: RE: [flexcoders] Beyond Confused (Please Help)- Flex 2 Beta 2 - HTTPService & 
XML


I tried compressing the entire project folder but I guess it was to big - it 
got kicked back and it was under 1 MB - pfff.  I am just sending the 2 MXML and 
XML files.  You should be able to add them to any project.

~David T.




From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Jason 
Hawryluk
Sent: Friday, March 31, 2006 2:57 PM
To: [email protected]
Subject: RE: [flexcoders] Beyond Confused (Please Help)- Flex 2 Beta 2 - 
HTTPService & XML


and the sample project
-----Message d'origine-----
De : [email protected] [mailto:[EMAIL PROTECTED] la part de David 
Terry Envoyé : vendredi 31 mars 2006 22:48 À : [email protected] Objet 
: RE: [flexcoders] Beyond Confused (Please Help)- Flex 2 Beta 2 - HTTPService & 
XML


Okay...  This is what I'm trying to understand.  So if my XML returns 'child' 
elements I can't use it in a DataGrid.  I found using FOR XML RAW handy for the 
DataGrid because I can get to all nested elements - essentially it returns rows.

But what about the Tree control - it expects a hierarchical data right?

I'm getting some very strange results with the Tree control bound a 
dataProvider of dataProvider="{MyDS}".

I'll attach a screenshot but I don't know if it will work.

~David T.





From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Jason 
Hawryluk
Sent: Friday, March 31, 2006 2:22 PM
To: [email protected]
Subject: RE: [flexcoders] Beyond Confused (Please Help)- Flex 2 Beta 2 - 
HTTPService & XML


Ya "Territory" that's one level deeper. In the grid I just tried to do 
dataField="Element.childElement" as well it did not work, but it did not 
explode either. I think your going to have to get your hands dirty with a 
cellrenderer to do that in a grid.

Binding this to a form would be a synch but a datafield I'm not sure if you can.

Hopefully someone else will shed some light. It certainly would be handy to be 
able to bind nested elements from multiple levels to a grid.

Jason

-----Message d'origine-----
De : [email protected] [mailto:[EMAIL PROTECTED] la part de David 
Terry Envoyé : vendredi 31 mars 2006 22:10 À : [email protected] Objet 
: RE: [flexcoders] Beyond Confused (Please Help)- Flex 2 Beta 2 - HTTPService & 
XML


Hi Jason,

I still don't see the Territory data.  I'm using the following XML Template...

<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">
    <sql:query>
 SELECT Employee.FirstName as FirstName, Employee.FirstName as label, 
Employee.LastName as LastName, SalesTerritory.Name as Territory, 
SalesPerson.TerritoryID as TerritoryID, SalesPerson.TerritoryID as 
label,SalesPerson.SalesPersonID as SalesPersionID, SalesTerritory.Name as label 
 FROM SalesPerson INNER JOIN
                Employee ON SalesPerson.SalesPersonID = Employee.EmployeeID 
INNER JOIN
                SalesTerritory ON SalesPerson.TerritoryID = 
SalesTerritory.TerritoryID  ORDER BY SalesTerritory.Name  FOR XML AUTO, ELEMENTS
    </sql:query>
 </ROOT>


The data is being returned like this...

  <?xml version="1.0" encoding="UTF-8" ?>
- <ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">
-     <Employee>
          <FirstName>Lynn</FirstName>
          <label>Lynn</label>
          <LastName>Tsoflias</LastName>
-         <SalesTerritory>
              <Territory>Australia</Territory>
              <label>Australia</label>
-                 <SalesPerson>
                      <TerritoryID>9</TerritoryID>
                      <label>9</label>
                      <SalesPersionID>36</SalesPersionID>
              </SalesPerson>
      </SalesTerritory>
  </Employee>
</ROOT>

Here is my code....

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"; xmlns="*" width="100%"
height="100%"
 creationComplete="rawXML.send();autoelementsXML.send()" >

 <mx:HTTPService
    id="rawXML" resultFormat="object"
    url="http://localhost/advwrk/templates/raw.xml";
    useProxy="false" showBusyCursor="true" />

    <mx:HTTPService
    id="autoelementsXML" resultFormat="e4x"
    url="http://localhost/advwrk/templates/autoelements.xml";
    useProxy="false" showBusyCursor="true" result="handleResults(event)"/>

    <mx:Script>
     <![CDATA[
      private function handleResults(event:Event):void{
       trace(event, "put break point here");
       }

     ]]>
    </mx:Script>

    <mx:XMLListCollection id="MyDS"
source="{autoelementsXML.result..Employee}"/>

 <mx:HBox x="10" y="10" width="100%" height="100%">
  <mx:VBox>
   <mx:Label text="FOR XML RAW"/>
   <mx:DataGrid dataProvider="{rawXML.result.ROOT.row}" height="300">
    <mx:columns>
     <mx:DataGridColumn headerText="First Name" dataField="FirstName"/>
     <mx:DataGridColumn headerText="Last Name" dataField="LastName"/>
     <mx:DataGridColumn headerText="Territory" dataField="Territory"/>
    </mx:columns>
   </mx:DataGrid>
  </mx:VBox>
  <mx:VBox>
   <mx:Label text="FOR XML AUTO, ELEMENTS"/>
   <mx:DataGrid dataProvider="{MyDS}" height="300">
    <mx:columns>
     <mx:DataGridColumn headerText="First Name" dataField="FirstName"/>
     <mx:DataGridColumn headerText="Last Name" dataField="LastName"/>
     <mx:DataGridColumn headerText="Territory"
dataField="SalesTerritory.Territory"/>
    </mx:columns>
   </mx:DataGrid>
  </mx:VBox>
 </mx:HBox>
</mx:Canvas>

Thanks again,
~David T.





From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Jason 
Hawryluk
Sent: Friday, March 31, 2006 1:24 PM
To: [email protected]
Subject: RE: [flexcoders] Beyond Confused (Please Help)- Flex 2 Beta 2 - 
HTTPService & XML


resultFormat="object"

change to

resultFormat="e4x"

The services will convert your xml to object value pair trees if you don't do 
this.

for a data grid your going to want the xmllist collection

example:

<mx:XMLListCollection id="MyDS" source="{rawXML..Employee}"/>

or


<mx:XMLListCollection id="MyDS" source="{rawXML.ROOT.Employee}"/>

your going to want the "FOR XML AUTO, ELEMENTS" if your getting your xml this 
way.

so then your grid becomes


<mx:DataGrid dataProvider="{MyDS}">
  <mx:columns>
          <mx:DataGridColumn headerText="First Name" dataField="FirstName"/>
          <mx:DataGridColumn headerText="Last Name" dataField="LastName"/>
          <mx:DataGridColumn headerText="Territory" dataField="Territory"/>
  </mx:columns>
</mx:DataGrid>

you may want to send the service results to a function so you can debug and see 
that it's what you really want


private function handleResults(event:Event):void{

trace("put break point here");

}

so your servcie is changed to

<mx:HTTPService
    id="rawXML" resultFormat="object"
    url="http://localhost/advwrk/templates/raw.xml";
    useProxy="false" showBusyCursor="true" result="handleResults(event)" />

If this does not get you started for the grid, post back here, and i'll give 
you some more help. Once you learn this it's basicly the same for a tree.
Again if you have problems with that as well, post back.

hope this helps

Jason

-----Message d'origine-----
De : [email protected] [mailto:[EMAIL PROTECTED] la part de David 
Terry Envoyé : vendredi 31 mars 2006 21:19 À : [email protected] Objet 
: [flexcoders] Beyond Confused (Please Help)- Flex 2 Beta 2 - HTTPService & XML


Hello everyone,

First off, thank you for reading this post and helping me understand this 
issue.  I am new to ActionScript coding but I've taken a very serious interest 
in RIA development using Flex.

Okay on to my issue.  I truly don't understand how Flex reads XML out of an 
HTTPService.  At times when trying to bind the data I only see [object Object]. 
 Other times I see what I need to display.  So...  For us newbie's how about we 
hack this out.

I'm using SQLXML IIS with XML Templates to return my SQL data using the FOR XML 
option in the select statement.  SQLXML IIS allows me to access my SQL Server 
via HTTP using various methods - I decided to use XML Templates for security 
issues.

XML Template Example
------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">
    <sql:query>
SELECT Employee.FirstName as FirstName, Employee.FirstName as label, 
Employee.LastName as LastName, SalesTerritory.Name as Territory, 
SalesPerson.TerritoryID as TerritoryID, SalesPerson.SalesPersonID as 
SalesPersionID
          FROM SalesPerson INNER JOIN
Employee ON SalesPerson.SalesPersonID = Employee.EmployeeID INNER JOIN
          SalesTerritory ON SalesPerson.TerritoryID = SalesTerritory.TerritoryID
          ORDER BY SalesTerritory.Name
          FOR XML AUTO, ELEMENTS
    </sql:query>
</ROOT>

I assume we all know TSQL but here is a little refresher on the FOR XML method. 
 FOR XML returns XML from SQL Server in various formats.

FOR XML RAW - Returns
------------------------------------------
  <?xml version="1.0" encoding="UTF-8" ?>
- <ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">
  <row FirstName="Lynn" label="Lynn" LastName="Tsoflias"
Territory="Australia" TerritoryID="9" SalesPersionID="36" />
  <row FirstName="José" label="José" LastName="Saraiva" Territory="Canada"
TerritoryID="6" SalesPersionID="31" />
  </ROOT>

FOR XML AUTO - Returns
------------------------------------------
  <?xml version="1.0" encoding="UTF-8" ?>
- <ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">
- <Employee FirstName="Lynn" label="Lynn" LastName="Tsoflias">
- <SalesTerritory Territory="Australia" label="Australia">
  <SalesPerson TerritoryID="9" label="9" SalesPersionID="36" />
  </SalesTerritory>
  </Employee>
  </ROOT>

FOR XML AUTO, ELEMENTS - Returns
------------------------------------------
  <?xml version="1.0" encoding="UTF-8" ?>
- <ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">
- <Employee>
  <FirstName>Lynn</FirstName>
  <label>Lynn</label>
  <LastName>Tsoflias</LastName>
- <SalesTerritory>
  <Territory>Australia</Territory>
  <label>Australia</label>
- <SalesPerson>
  <TerritoryID>9</TerritoryID>
  <label>9</label>
  <SalesPersionID>36</SalesPersionID>
  </SalesPerson>
  </SalesTerritory>
  </Employee>
  </ROOT>

Okay with that said here is what I am trying to do.

I want to databind a control (DataGrid and Tree in these examples) with the 
results.  Here is my Flex code.

<mx:HTTPService
    id="rawXML" resultFormat="object"
    url="http://localhost/advwrk/templates/raw.xml";
    useProxy="false" showBusyCursor="true" />

<mx:DataGrid dataProvider="{rawXML.result}">
  <mx:columns>
          <mx:DataGridColumn headerText="First Name" dataField="FirstName"/>
          <mx:DataGridColumn headerText="Last Name" dataField="LastName"/>
          <mx:DataGridColumn headerText="Territory" dataField="Territory"/>
  </mx:columns>
</mx:DataGrid>

Now...  This fails (I don't see any results), but if I place the results in a 
Text...

<mx:Text text="{rawXML.result}"/>
 I get [object Object]

If I change the code to <mx:Text text="{rawXML.result.ROOT}"/> It still 
displays [object Object].

But, changing it to <mx:Text text="{rawXML.result.ROOT.root}"/> returns many 
[object Object] values.

Using a dataProvider of dataProvider="{rawXML.result.ROOT.root}" in the 
DataGrid returns the results I expect, but lets say I was using the FOR XML 
AUTO, ELEMENTS data with the dataProvider of 
dataProvider="{rawXML.result.ROOT.Employee}" I also get data, BUT I can't get 
the Territory data.  It seems I only have access to the Employee node of the 
tree and not children nodes.

Hold on to that though...

Lets try using a Tree control with the dataProvider set to 
dataProvider="{rawXML.result.ROOT.Employee}" using the FOR XML AUTO, ELEMENTS 
data.

<mx:Tree dataProvider="{rawXML.result.ROOT.Employee}" />

Now based on the examples I've seen I should have seen a Tree that looks kind 
of like...

Employee
          Territory
                   ID

BUT...  It seems I have the same problem as the DataGrid and can only see the 
Employee level of the XML.

I have no idea what I am doing wrong.

My Questions
---------------------------------
How does Flex handle XML?
Why doesn't Flex understand the XML?
Am I doing something wrong?
Do I need to convert the data into something?
Am I missing a step?

ANY help would be GREATLY appreciated.

Many thanks,
~David T.






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS

 Visit your group "flexcoders" on the web.

 To unsubscribe from this group, send an email to:
 [EMAIL PROTECTED]

 Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.





--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links



 




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to