Dynamic XML filtering based on params

馋奶兔 提交于 2019-12-13 06:21:31

问题


Follow up question on Filtering XML based on multiple params - Flex.

I was trying to create the Query part dynamically so that params and the keys take over for building the criteria part. Just to show:

 //building a dynamic query like this 
var q1:String = "descendants (\"E1" ) == \"111\" )"; 
Alert.show("Query>>"+q1.toString());     // Output: descendants ("E1" ) == "111"

var r2:XMLList = xmlData..*.(descendants ("E1" ) == "111"); //returns correct result 
var r1:XMLList = xmlData..*.(q1.toString());  // weird response, 
                                              // doesn't filter out anything

A comment here Filtering XML based on multiple params - Flex says that the expression inside the parentheses should not be a string. Agreed.

So, is there any other approach to filter out multiple parameters in XML than to use the descendants(), which currently is not working out because we are building the search query dynamically, based on the params searched?

Any pointers/ideas would be of great help.


回答1:


How about doing the filtering in a loop?

var filters : Array = [ { key : "E1", value : "333" }, { key : "D1", value : "333" } ];

var searchItem : XMLList = xmlData.*;
for each (var filter:Object in filters)
    searchItem = searchItem.( descendants ( filter.key ) == filter.value);

trace (searchItem);


来源:https://stackoverflow.com/questions/9185413/dynamic-xml-filtering-based-on-params

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!