is possible use variables in xml node queries within actionscript 3?
given following rss feed structure:
<?xml version="1.0" encoding="utf-8"?> <rss xmlns:atom="http://www.w3.org/2005/atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0"> <channel> <item> <media:content url="http://www.example.com/test.jpg" type="image/jpeg" height="683" width="1024" /> <media:content url="http://www.example.com/test2.jpg" type="image/jpeg" height="683" width="1024" /> </item> </channel> </rss> the following code works intended, displaying url attribute value first content node within media namespace:
var nsattribute:string = 'media'; var nodename:string = 'content'; var holder:string = 'item'; var imagepathattribute = 'url'; // pull namespace attribute value xml declaration var ns:string = rssxml.namespace(nsattribute); // make namespace instance based on xpl namespace's uri var imagepathnamespace:namespace = new namespace( ns ); trace ( rssxml.channel.child(holder).imagepathnamespace::content[0].@url ); returns expected result:
http://www.example.com/test.jpg however, when use variables in path node, error.
trace ( rssxml.channel.child(holder).imagepathnamespace::nodename[0].@imagepathattribute ); the error receive is:
typeerror: error #1010: term undefined , has no properties. probably because can't find value index because path returns empty string. if remove index section "[0]" path, returns empty string.
so how use variables in xml query? reason i'm trying make class i'm working on extensible enough need set properties of class, can work different rss feed types , not have hard-code each specific feed.
thank assistance can offer.
what need like:
var node:xml = rssxml.channel.child(holder).imagepathnamespace::content[0]; trace(node.attribute(imagepathattribute)); you can manipulate directly attributes , node names using xml object methods. using that, can provide variables functions.
Comments
Post a Comment