Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Data Grid XML filtering

New Here ,
Feb 24, 2010 Feb 24, 2010

I cant sem to figure out how to filter my XML data before entering my data grid. I want to load only the XML data with the ID attribute "BALUSTER" and have tried entering:

data_grid.dataProvider = dp.(@ID == "BALUSTER");

into my xmlLoaded function without any success.  I am fairly new to as3 and could definitely use the help.  Thanks.

var dpataProvider;
var products_xml:XML;
var xmlReq:URLRequest = new URLRequest("data/products.xml");
var xml_loader:URLLoader = new URLLoader();

function xmlLoaded(event:Event):void {
var ldr:URLLoader = event.currentTarget as URLLoader;
var xmlDP:XML = new XML(ldr.data);
dp = new DataProvider(xmlDP);
data_grid.dataProvider = dp;
}

xml_loader.load(xmlReq);
xml_loader.addEventListener(Event.COMPLETE, xmlLoaded);

TOPICS
ActionScript
810
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Feb 25, 2010 Feb 25, 2010

Assign the filtered data (not the original) to the data provider:

function xmlLoaded(event:Event):void {
    var ldr:URLLoader = event.currentTarget as URLLoader;
    var xmlDP:XML = new XML(ldr.data);
   
    var data:XML = <PRODUCTS/>;
    data.setChildren(xmlDP.PRODUCTS.(@ID == "BALUSTER"));
   
    dp = new DataProvider(data);
    data_grid.dataProvider = dp;
}

Translate
Guest
Feb 25, 2010 Feb 25, 2010

Hard to say without seeing your xml, but something along these lines might work for you:

import fl.data.DataProvider;

var rawXml:XML =
<xml>
<item ID="BALUSTER">
  <moniker>bubba</moniker>
  <age>50</age>
</item>
<item ID="BALUSTER">
  <moniker>bobby-sue</moniker>
  <age>13</age>
</item>
<item ID="BULLUSTER">
  <moniker>boo</moniker>
  <age>25</age>
</item>
</xml>;

// use a second XML object to hold the selected nodes

var data:XML = <data/>;
data.setChildren(rawXml.item.(@ID == "BALUSTER"));

var dp:DataProvider = new DataProvider(data);
data_grid.dataProvider = dp;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2010 Feb 25, 2010

My xml data is on an external file, hence:

var xmlReq:URLRequest = new URLRequest("data/products.xml");
var xml_loader:URLLoader = new URLLoader();

My xml data is written:

<PRODUCTS ID="BALUSTER" TYPE="3-5/8&quot; System" PART="HBAL 600-20" WIDTH="2-1/4&quot;" HEIGHT="20&quot;" REMARKS="*custom lengths available"/>
    <PRODUCTS ID="BALUSTER" TYPE="3-5/8&quot; System" PART="HBAL 600-24" WIDTH="2-1/4&quot;" HEIGHT="24&quot;" REMARKS="*custom lengths available"/>

I want to load only the products with the "id" == "baluster" into the data grid.  If I were to load it into text field, I know I can use something like:

myText_txt.text = xmlDP.PRODUCTS.(@ID=="BALUSTER").parent();

but I cant figure out how to load this into a Data Grid instead.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 25, 2010 Feb 25, 2010

... then this should work:

function xmlLoaded(event:Event):void {
var ldr:URLLoader = event.currentTarget as URLLoader;
var xmlDP:XML = new XML(ldr.data);

var data:XML = <data/>;
data.setChildren(xmlDP.PRODUCTS.(@ID == "BALUSTER"));

dp = new DataProvider(data);
data_grid.dataProvider = dp;
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2010 Feb 25, 2010

So if my XML data is similar to this . . .

<PRODUCTS>

     <PRODUCTS ID="BALUSTER" TYPE="3-5/8&quot; System" PART="HBAL 600-20"/>
     <PRODUCTS ID="BALUSTER" TYPE="3-5/8&quot; System" PART="HBAL 600-24"/>

     <PRODUCTS ID="BRACKETS" TYPE="3-1/4&quot; to 3-5/8&quot; System" PART="HTR 232"/>

</PRODUCTS>

I tried this . . .

function xmlLoaded(event:Event):void {
    var ldr:URLLoader = event.currentTarget as URLLoader;
    var xmlDP:XML = new XML(ldr.data);
   
    var data:XML = <PRODUCTS/>;
    data.setChildren(xmlDP.PRODUCTS.(@ID == "BALUSTER"));
   
    dp = new DataProvider(xmlDP);
    data_grid.dataProvider = dp;
}


. . . but its still not filtering only "BALUSTER" products.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 25, 2010 Feb 25, 2010

Assign the filtered data (not the original) to the data provider:

function xmlLoaded(event:Event):void {
    var ldr:URLLoader = event.currentTarget as URLLoader;
    var xmlDP:XML = new XML(ldr.data);
   
    var data:XML = <PRODUCTS/>;
    data.setChildren(xmlDP.PRODUCTS.(@ID == "BALUSTER"));
   
    dp = new DataProvider(data);
    data_grid.dataProvider = dp;
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2010 Feb 25, 2010

It worked!  Thanks, been struggling for a few days on this!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 25, 2010 Feb 25, 2010
LATEST

You're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines