Hello,
To read you xml string you must use the XML class (check the help it's quite clear). It's far much more simple than on AS2 so enjoy it ;)

Regards
Fred


On 3/31/06, David Terry <[EMAIL PROTECTED]> wrote:

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="" href="http://localhost/advwrk/templates/raw.xml" target="_blank" >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




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


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




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to