Hello everyone,
First off, thank you for reading
this post and helping me understand
this issue. I am new to
ActionScript coding but Ive taken a very
serious interest in RIA development
using Flex.
Okay on to my issue. I truly dont 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 newbies how about we hack this
out.
Im 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="
<row FirstName="José" label="José"
LastName="Saraiva" Territory="
</ROOT>
FOR XML AUTO Returns
------------------------------------------
<?xml version="1.0" encoding="UTF-8"
?>
- <ROOT
xmlns:sql="urn:schemas-microsoft-com:xml-sql">
- <Employee
FirstName="
- <
<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>
<LastName>Tsoflias</LastName>
-
<SalesTerritory>
<Territory>
<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=""
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 dont 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 cant 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 Ive 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 doesnt 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
| Web site design development | Computer software development | Software design and development |
| Macromedia flex | Software development best practice |
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.

