xml - How do I filter by attribute and value across multiple elements? -
i'm trying find xml node checking it's type (type attribute). can following code:
var xml:xml = describetype(this); var classname:string = getqualifiedclassname(maingroup); var xmllist:xmllist = xml.accessor.(@type==classname); if (xmllist.length()) { trace("found:" + xmllist[0]); }
but not know if "accessor" element. "variable" element or possibly else. want search elements in xml have type attribute has value matches value i'm looking for. when use following says it's invalid:
// 1084: syntax error: expecting doublecolon before semicolon. var xmllist:xmllist = xml..(@type==classname);
what correct syntax information i'm looking for?
here xml test with:
<type name="myapplication" base="spark.components::windowedapplication" isdynamic="false" isfinal="false" isstatic="false"> <accessor name="explicitminwidth" access="readwrite" type="number" declaredby="mx.core::uicomponent"/> <accessor name="maingroup" access="readwrite" type="components::maingroup" declaredby="myapplication"> </accessor> <variable name="controlbargroup" type="spark.components::group"> </variable> </type>
what using *
:
var xml:xml = <type name="myapplication" base="spark.components::windowedapplication" isdynamic="false" isfinal="false" isstatic="false"> <accessor name="explicitminwidth" access="readwrite" type="number" declaredby="mx.core::uicomponent" /> <accessor name="maingroup" access="readwrite" type="components::maingroup" declaredby="myapplication" /> <variable name="controlbargroup" type="spark.components::group" /> <variable name="explicitminwidth" access="readwrite" type="number" declaredby="mx.core::uicomponent" /> </type>; var xml_list:xmllist = xml.*.(@type == 'number'); trace(xml_list.length()); // gives : 2
edit :
to avoid error error #1065: variable type not defined
, drop lines didn't contain type
attribut, can use :
var xml_list:xmllist = xml.*.(attribute('type') == 'number'); trace(xml_list.length()); // gives : 2
hope can help.
Comments
Post a Comment