tags:

views:

26

answers:

1

I have some xml and I am trying to filter it using e4x. My e4x statement looks like this:

model.config.source.fees..fee.(@min<amount).@amount

My xml looks liks this:

<flex>
  <fees>
    <fee type="credit" min="0.00" max="200.00" amount="6.00"/>
    <fee type="credit" min="200.01" max="370.00" amount="10.00"/>
  </fees>
</flex>

When the e4x statement is run, I get an error message: Error #1065: Variable @min is not defined.

But if I change my statement to model.config.source.fees..fee.@min it will return an xmllist of all the min attribute values, so min is defined, at least in that statement. Why doesnt the original statement work?

+2  A: 

When you use @min<amount it requires that all fee nodes have the min attribute defined. It works for your example xml but maybe you were missing @min in your other test data.

However, if you use this format:

model.config.source.fees..fee.(parseFloat(attribute('min')) < amount).@amount

It will handle all nodes whether the attribute is there or not.

Dave
I tried this statementmodel.config.source.fees..fee.(attribute('min')==0).@amountand it is returning an XMLList. If I do this model.config.source.fees..fee.(attribute('min')==0)[email protected](); it is an empty string?
Chris
Good catch, edited answer adding parseFloat in there.
Dave