Page 1 of 1
undefined is not an object in E4X xml parsing
Posted: October 1st, 2007, 9:51 am
by bradshaw1965
I'm having some unexpected results in some E4X XML parsing. I'm getting an error
undefined is not an object.
Typically, I would check for undefined, like so
but that doesn't seem to be working, additionally if I check explicitly
Code: Select all
if(filters[child].effect.name != undefined)
Code: Select all
if(filters[child].effect.name != null)
nope
checking for an xml node
Code: Select all
if(filters[child].contains(effect)){
no go
I get the same error. Also, this style check seems to be working in other cases. Am I getting moved off the track by some other condition that I'm not accounting for?
1:21 p.m. followup
a little more info about what I'm doing. I'm iterating xml nodes in a for in construct.
Code: Select all
var filters = clip.filter;
if(filters){ //this style undefined works here
for(child in filters){
//if I do a alert(typeof filters[child]) here I get a series of xml nodes and then a final undefined node which I think is my problem.
}
}
why am I getting a non-xml node at the end of this child list and why does it resist being checked in the conditional?
1:53 pm follow up
So, the basis of all my problems was a bug in logic
should have been
Code: Select all
var filters = clip.filter.children();
but I"m still unclear why a conditional would fail if the condition is being met. It didn't exist so it was undefined, was it the nested looping structure? Sorry to be thinking out loud and in public.
Posted: October 1st, 2007, 5:11 pm
by nab
wow, is it a script for AE ?
looks like new school technique, what file are you parsing that way ?
Posted: October 1st, 2007, 5:55 pm
by bradshaw1965
I'm parsing Final Cut XML files. E4X XML parsing is now native in CS3 Extendscript and it kicks all kinds of ***. All of the stuff I was converting to JSON are now native objects, with great iterators and really intuitive access to the tree. You've even got namespaces, so all the mulitple flavors of RSS, like in
kuler are supported nicely especially when combined with the new
HttpConnection object in Extendscript
The best overview of E4X style XML parsing I've seen is in Colin Moock's
Essential Actionscript 3, although the Extendscript version is a subset of full E4X and a few examples differ slightly in their implementation, it gives a great overview in Moock's accessible style.
A quick heads up when you start digging into it,
toString(),parseInt(), parseFloat(), isInt(), isNaN(), isFloat() are your friends. I love duck typing mostly in Javascript, but a little stronger typing when you go from XMLlist, to XMLNode, to Object, to String, to Number would be really handy.
E4X
Posted: October 1st, 2007, 10:58 pm
by redefinery
bradshaw1965 wrote:var filters = clip.filter.children();
hey dale... is .filter your <filter> tag, and you're trying to retrieve the contents of that node? the contents should be a text node, so i would think .filter.text() would work.
bradshaw1965 wrote:You've even got namespaces, so all the mulitple flavors of RSS, like in
kuler are supported nicely especially when combined with the new
HttpConnection object in Extendscript
how are you using HttpConnection? i don't think Web Access Library is available for AE CS3. or, are you using the Socket object to retrieve the XML data, and then using the E4X stuff to process it?
:jeff
Re: E4X
Posted: October 2nd, 2007, 5:49 am
by bradshaw1965
Hey Jeff,
redefinery wrote:
hey dale... is .filter your <filter> tag, and you're trying to retrieve the contents of that node? the contents should be a text node, so i would think .filter.text() would work.
Thanks for the reply. If I replace
with
Code: Select all
if(filters[child].effect.name.text())
I still get
undefined is not an object when it can't find that particular node. the nodes are structured where there will always be a filter node, but not always a filter.effect.name node (sometimes it is nested further in the node and I'm getting a syntax error using the .. style access, is this expected?) , and I was hoping for a shorthand undefined like I'm familar with in Javascript, at this point I'd settle for a long hand undefined, but I can't seem to get anything to work except putting it into a try/catch and eating the exception. None of which seems right so I went here for a sanity check. I'm sure I'm doing something incorrectly.
how are you using HttpConnection? i don't think Web Access Library is available for AE CS3. or, are you using the Socket object to retrieve the XML data, and then using the E4X stuff to process it?
ahh, really? unfortunately I was abstracting that away after seeing it in the docs. I've been working with xml literals while I get the parsing part figured out. I've had some success with the socket object which should work for the REST style projects I've got in mind, but simplified authentication would be really nice.
Thanks again,
Dale
Posted: October 2nd, 2007, 5:59 am
by bradshaw1965
ok, one more followup.
Like I was saying there will always be a filter, and typically I use a
to iterate the children of the xmlList. In this case though some instances of filters[child] are undefined. If I explore the instances of filters it definitely has children when it's undefined, the xml validates, it's trying to enter the constuct.
so this code works
Code: Select all
for(child in filters){
if(filters[child]){
}
}
Which is just really weird. I'd question the xml if it wasn't valid..no weird entities, no processing instructions etc. something is causing an edge case here though.
xml
Posted: October 2nd, 2007, 6:52 am
by redefinery
bradshaw1965 wrote:I'd question the xml if it wasn't valid..no weird entities, no processing instructions etc. something is causing an edge case here though.
hey dale... maybe it's my unfamiliarity with E4X (or it being a little early in the morning here in seattle

), but i'm not totally following what you're trying to do. can you e-mail me (at my work acct) some sample XML and JSX code snippets?
thanks.
Posted: October 2nd, 2007, 6:54 am
by bradshaw1965
Hey Jeff,
will do. I realize I've gotten pretty far afield.
Thanks,
Dale