0

I'm trying to solve an Actionscript problem using 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?

Pierre
  • 1

2 Answers2

0

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

Eli Grey
  • 35,104
  • 14
  • 75
  • 93
0

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.

Pierre
  • 1