Hi everyone,

 

I have this problem trying to extract child nodes from an XMLDocument object, and displaying them in a datagrid.  In my code, I have a simple XML string, which I turn into an XMLDocument object using xml_object.parse(xml_string).  That works fine.  Now I want to display the relevant data items in a datagrid.  So, I simply make a datagrid and set the xml object as the data provider, giving it the point where the SearchResultItem tag starts, so that will be the array of repeating items.  This also works, but not in the way I would like it to appear.  So I tried to set the columns, however, when I do this, I get nothing returned.  This is the block of commented code at the bottom of the application.  If you can see what I'm trying to do, all I am doing is trying to access the child nodes of the Item, but it won't let me.  Someone please help me...it's driving me nuts!

 

The source and .swf files can be downloaded here, so you can see just what I'm talking about...

< http://charles.abstractations.com/test.zip >

 

Here is my code...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml" creationComplete="ParseXML()">
 <mx:Script>
  <![CDATA[
   import flash.xml.XMLDocument;

   [Bindable] public var xml_object:XMLDocument = new XMLDocument;
   [Bindable] public var xml_string:String =
     "<?xml version='1.0' encoding='UTF-8' ?>" +
     "<GetSearchResultsResponse>" +
     " <Timestamp>2006-05-26T16:34:26.994Z</Timestamp> " +
     "   <Ack>Success</Ack> " +
     "  <SearchResultItemArray>" +
     "   <SearchResultItem>" +
     "    <Item>" +
     "      <ItemID>110000084705</ItemID> " +
     "    <Title>Halo 2 for Xbox</Title>" +
     "    <Details>" +
     "     <Info>Like new, includes instruction manual</Info>" +
     "    </Details>" +
     "   </Item>" +
     "   <SearchResultValues>New</SearchResultValues> " +
     "  </SearchResultItem>" +
     "  <SearchResultItem>" +
     "    <Item>" +
     "      <ItemID>110000084752</ItemID> " +
     "    <Title>Halo 1 for Xbox</Title> " +
     "    <Details>" +
     "     <Info>Minor scratches, plays perfectly</Info>" +
     "    </Details>" +
     "   </Item>" +
     "     <SearchResultValues>New</SearchResultValues> " +
     "    </SearchResultItem>" +
     " </SearchResultItemArray>" +
     "   <ItemsPerPage>100</ItemsPerPage> " +
     "   <PageNumber>1</PageNumber> " +
     "   <HasMoreItems>false</HasMoreItems> " +
     " </GetSearchResultsResponse>";
 
   public function ParseXML():void
   {
    xml_object.ignoreWhite=true;
    xml_object.parseXML(xml_string);
    
    search_results_grid.dataProvider=xml_object.firstChild.firstChild.nextSibling.nextSibling.childNodes;
   }
  ]]>
 </mx:Script>

 <mx:DataGrid id="search_results_grid" height="400" width="100%" selectedIndex="0" >
  <!--
  <mx:columns>
   <mx:DataGridColumn headerText="Item ID" dataField="Item.ItemID" />
   <mx:DataGridColumn headerText="Title" dataField="Item.Title" width="175" />
   <mx:DataGridColumn headerText="Details" dataField="Item.Details.Info" width="175" />
  </mx:columns>
  -->
 </mx:DataGrid>
 <mx:Spacer height="15" />
 
</mx:Application>

Thanks in advance!



--
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