开发者

Wildcard for Strings in E4X?

开发者 https://www.devze.com 2023-02-07 05:26 出处:网络
I\'m trying to solve an Actionscript problem usin开发者_开发技巧g E4X. I have an XML like this one:

I'm trying to solve an Actionscript problem usin开发者_开发技巧g E4X. I have an XML like this one:

<root>
  <person firstname="john" lastname="doe" age="21" />
  <person firstname="jayne" lastname="doe" age="35" />
  <person firstname="john" lastname="miller" age="42" />
</root>

I want to have just one function search() that takes three parameters (firstname, lastname, age) and return an XMLList. So the result could look like this:

var result:XMLList = xml..person.(@firstname == firstName && @lastname == lastName && @age == age );

But I don't want to use all three parameters all the time. I would like to have a function that uses a 'wilcard' if the parameter is NULL. So if the wildcard would be "*" the function could look like:

searchPerson( firstName:String ="*", lastName:String = "*" , age:String = "*") {...}

so that I would only pass 'John' for the firstName I'd get the first and the third node in return.

How to do so?


The boolean value of attribute("your-attribute") will indicate if a particular attribute is present.


Ok. I could check all attributes. But I would be left with 7 different options:

  • firstName
  • secondName
  • age
  • firstName && secondName
  • firstName && age
  • lastName && age
  • firstName && secondName && age

I'd prefer a one-liner, that's why I'm looking for something like a wildcard.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号