<fx:XML id="dataGridDataFieldsXML" source="assets/dataGridDataFieldsXML.xml"/>
<s:XMLListCollection id="showGridFields" source="{dataGridDataFieldsXML.viewer}"/>
I want to loop through my 开发者_如何学编程XML file and get the "field" value.I tried the following but nothing is getting through the trace statement:
var xmlTrack:XML;
for each( xmlTrack in dataGridDataFieldsXML.fields_by_viewer.viewer )
{
trace(xmlTrack.@field);
}
My XML
<?xml version="1.0" encoding="UTF-8"?>
<fields_by_viewer>
<viewer id="1" field="fieldName1"/>
<viewer id="1" field="fieldName2"/>
</fields_by_viewer>
Anything wrong here?
Thanks
flexyboz
Try the following:
var myXML:XML = <users>
<fname>Jane</fname>
<fname>Susan</fname>
<fname>John</fname>
</users>;
for each (var item in myXML.fname)
{
trace(item);
}
/* output
More to be found here: http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_16.html
@Craig Mc..this works fine.
I also tried:
fieldsXMLListNew=new XMLListCollection(dataGridDataFieldsXML.viewer as XMLList);
And then looped and got my items using:
for each(var item in fieldsXMLListNew){
item.attribute("field");
}
精彩评论