Re: [Flashcoders] empty XML Attributes..
I think that's not exactly correct. You can use "@" to access non-existence attributes but cannot use it for filtering. With the OP example, trace(_co...@instance); ...should not generate an error but you'd get an error with: trace(_conf.(@instance == "boo")); ...so instead this should be used: trace(_conf.(attribute("instance") == "boo")); Kenneth Kawamoto http://www.materiaprima.co.uk/ Steven Sacks wrote: You will get runtime errors when attempting to access an attribute that isn't there. The proper way to check for existence and length of an attribute is to use the .attributes() syntax as such: if (node.attribute("instance").length() > 0) ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] empty XML Attributes..
Unfortunately, that doesn't work. That returns something (an empty XMLList, I believe). The best way to test for attribute existence and/or if it has a value is what I wrote. Glen Pike wrote: Thanks for the answers with the length() thing - I tried out a few of those and got working thing You're suggesting to write more code to do the same thing. Why should anyone write more code to do the same thing? With the above comment in mind - I was trying to do if(no...@attribute) which I thought would be the simplest most sensible way of doing - if something does not exist, why return an object / value? I could test for undefined, but that did not seem to work, I will try again though... Thanks. Glen ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] empty XML Attributes..
Thanks for the answers with the length() thing - I tried out a few of those and got working thing You're suggesting to write more code to do the same thing. Why should anyone write more code to do the same thing? With the above comment in mind - I was trying to do if(no...@attribute) which I thought would be the simplest most sensible way of doing - if something does not exist, why return an object / value? I could test for undefined, but that did not seem to work, I will try again though... Thanks. Glen ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] empty XML Attributes..
hasOwnProperty does not tell you whether it has a length, though. It only checks for existence. And for some reason, it looks like you modified my code when quoting me: >> if (node.hasOwnProperty("instance").length() > 0) I didn't write that code, which would error since a Boolean doesn't have length(). I wrote this: if (node.attribute("instance").length() > 0) Which not only works, but is the recommended way of writing this code by Adobe themselves directly from the E4X documentation. You're suggesting to write more code to do the same thing. Why should anyone write more code to do the same thing? ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] empty XML Attributes..
The Top Level XML class actually has a function, called hasOwnProperty that exists for this purpose. However, to answer your question exactly, it returns a value of undefined. This is not null or "" it is it's own return type, as this relates to XML (which by definition is an object) and objects are dynamic. Null would only be returned if you've already declared a variable but it has no value, undefined is returned for something that you have not declared. So in addition to Steven's method, you could also do: if (node.hasOwnProperty("@instance")) or if (no...@instance != undefined) - Taka On Wed, Aug 26, 2009 at 6:06 PM, Steven Sacks wrote: > You will get runtime errors when attempting to access an attribute that > isn't there. The proper way to check for existence and length of an > attribute is to use the .attributes() syntax as such: > > if (node.hasOwnProperty("instance").length() > 0) > > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] empty XML Attributes..
You will get runtime errors when attempting to access an attribute that isn't there. The proper way to check for existence and length of an attribute is to use the .attributes() syntax as such: if (node.attribute("instance").length() > 0) ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] empty XML Attributes..
On Wed, Aug 26, 2009 at 12:27 PM, Glen Pike wrote: > Aha, I see now - bit of a waste of code too. Yeah, I agree, it's overly verbose. > And who's bright idea was it to use length for Strings and Arrays, but > length() for XML / e4x? It's because in E4X: someNode.length Means get this node: :-) The brackets () are the only way to work out what you mean... Ian ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] empty XML Attributes..
Aha, I see now - bit of a waste of code too. And who's bright idea was it to use length for Strings and Arrays, but length() for XML / e4x? Kenneth Kawamoto wrote: XMLList, and you can check its length(). Kenneth Kawamoto http://www.materiaprima.co.uk/ Glen Pike wrote: Hi, I am having problems parsing some XML config files and testing for empty attributes. There is an example xml below. Problem is that I am asking for the following: _co...@instance Which is returning a value, but I am not sure what type of value. Should this return null, or an empty string or something?? var _conf:XML =swf="LibraryScreenTest.swf" symbol="com.robothespian.screen.LibraryScreen" config="library.xml" /> Glen ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] empty XML Attributes..
XMLList, and you can check its length(). Kenneth Kawamoto http://www.materiaprima.co.uk/ Glen Pike wrote: Hi, I am having problems parsing some XML config files and testing for empty attributes. There is an example xml below. Problem is that I am asking for the following: _co...@instance Which is returning a value, but I am not sure what type of value. Should this return null, or an empty string or something?? var _conf:XML =swf="LibraryScreenTest.swf" symbol="com.robothespian.screen.LibraryScreen" config="library.xml" /> Glen ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders