Hi Pedro,

 

Sorry about that. This should be the correct solution.

 

idHTTPService.lastResult.record.(subject.(@id=="c001").length())

 

Again, the important distinction between XPath and E4X is that E4X is
essentially an object representation of the XML. Here are a few E4X "rules"
that I've learned along the way, I'll probably try to expand on this more
and make a post on it sometime.

 

-          All E4X statements will return an XMLList object. E4X with no
results will return a blank XMLList object.

-          XMLList objects with only one child node can be treated as XML
objects (which is why you would get results when records had only one child,
but I don't think E4X statements should ever depend on this functionality).

-          Any filter (items in parenthesis) will be evaluated as a Boolean
value inside the context of each child from the E4X to which it's applied.
False results are filtered out. You can put anything in a filter really; it
doesn't have to be more E4X.

-          Blank XMLList objects are still evaluated as true (non-null) in a
filter (which is why I used the length() method, this way blank XMLList
objects will return a length of 0 which evaluates as false).

 

I think making a transition from XPath to E4X is probably harder than just
learning E4X with no background, simply because developers have an
expectation of syntax and functionality similar to XPath. There is some
quirky behavior in comparison, but hopefully it's not that hard once you
realize you're just working with XMLList objects.

 

Ben Stucki

---------------------------------
We're Hiring! Seeking a passionate developer to join our team building Flex
based products. Position is in the Washington D.C.  
metro area. If interested contact [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> l.com

  _____  

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Pedro Pastor
Sent: Saturday, February 10, 2007 4:19 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: New to the group

 

Hi Ben,

Thank you very much for your response. Here you are my comments: 

1) The "=" / "==" error is just a typing error in my e-mail. This
symbol was properly set in my code.

2) I've tried your suggestion but it doesn't work. That query provides
ALL the <record> elements in the XML tree. Using the very same code
but removing the internal "()" for the (@id == "c001") filter, it
provides me with the matching <record> elements BUT only those having
ONLY ONE <subject> children (and having @id = "c001").

3) The point is I need to check (filter) at children level (<subject>)
in order to get the appropriate parent node-set (<record>). That's
very easy in XPath, but I'm getting quite confusing with E4X. 

I've been developing XML application form years, and I've been dealing
with XML+XSLT+ . some other dynamic HTML technologies and I find
Flex+ActionScript is a big step forward in the client web application
realm, but the way ActionScript deals with XML is a bit deceiving.

Best regards,

Pedro

--- In [EMAIL PROTECTED] <mailto:flexcoders%40yahoogroups.com> ups.com,
"Ben Stucki" <[EMAIL PROTECTED]> wrote:
>
> 
> Hey Pedro,
> 
> Welcome to FlexCoders!
> 
> I came into E4X with a background in XPath as well and think the
> biggest hurdle in learning E4X was understanding the methodology behind
> it. XPath is intended as a query language for XML. In contrast I think
> of E4X more like an object representation of XML. This means it can
> treat results a little differently based on the form of the XML , such
> as when you get results with only one subject node but not with
> multiple subject nodes. I've found that while I work with XPath from
> the top down, I get the best results from E4X when I check it from the
> inside out. Here's how the original query works out.
> 
> idHTTPService.lastResult.record
> 
> .(
> 
> [EMAIL PROTECTED]"c001")
> 
> The inner most part is @id="c001". The main problem with this is that
> it uses the assignment (=) operator and not evaluation (==). This means
> that istead of looking for an id attribute value of "c001", it's
> actually creating or overrideing the id attribute. So we'll change that
> to ==.
> 
> idHTTPService.lastResult.record
> 
> .(
> 
> [EMAIL PROTECTED]"c001")
> 
> The next part to evaluate is [EMAIL PROTECTED]"c001". The problem here is
> that while @id=="c001" is meant as a filter, it's not in parenthesis.
> So we'll change that to subject.(@id=="c001") .
> 
> The rest works already, so here's the end result.
> 
> idHTTPService.lastResult.record
> 
> .(
> 
> subject.(@id=="c001"))
> 
> It takes a little getting used to, but I've found that E4X can
normally handle what I need it to do.
> 
> Ben Stucki

 

Reply via email to