say, I have an xml like as follows:
public static var keywords:XML = <keywords>
<tag key="html" type="tag"/>
<tag key="htmlNew" type="attr"/>
<tag key="head" type="attr"/>
<tag key="body" type="attr"/>
</keywords>;
I need to search this xml by attribute value. If user provides input as "html" then I need to return both <tag key="html" type="tag"/> <tag key="htmlNew" type="attr"/>
node as XMLList. It kind of start with type searching by xml attribut开发者_如何学编程e. Please anybody provide any kind of solution or suggestion. for direct attribute matching I have used following code:
var closeMatchList:XMLList = xml.tag.(@key == "html") as XMLList;
It returns only <tag key="html" type="tag"/>
tag
Is this kind of solution is possible?? please anybody provide any kind of solution. I am stuck with this problem for long time. thanks in advance.
Without third party libraries you could also do this:
keywords.tag.(attribute("key").indexOf("html")==0)
There is an XPath library for ActionScript3 (xpath-as3) that can do this easily.
public static var keywords:XML = ...;
var thePath:String = "/keywords/tag[starts-with(@key, 'html')]";
var html:NodeSet = XPath.evaluate(thePath, keywords);
Some other ways to use the library can be seen over here.
精彩评论