PDA

View Full Version : colon's in nod names of XML files {Help please}



joshchernoff
August 5th, 2007, 05:52 PM
I have to use array access notation when accessing the kuler API rss feed because they name there nodes things like "<kuler:themeItem>" and that dam colon messes every thing up.

any ideas to work around this?



var myLoader:URLLoader;
var myXML:XML
var urlRequest:URLRequest;

myXML = new XML();
urlRequest = new URLRequest("http://kuler.adobe.com/kuler/services/rss/search.cfm?searchQuery=joshchernoff&startIndex=0&itemsPerPage=100&displayfull=true&readerType=widget");
myLoader = new URLLoader(urlRequest);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event:Event):void {
myXML = XML(myLoader.data);
trace(myXML.channel.item.length());//[0].title

//Will trace out the hole XML doc
//trace(XML(myLoader.data));

for (var i:uint = 0; i < myXML.channel.item.length(); i++) {

//Will trace out every item nod.
//trace(myXML.channel.item[i]);

trace(myXML.channel.item[i].title);
trace(myXML.channel.item[i].kuler);
trace(myXML.channel.item[i]["kuler:themeItem"]);// the nod name "kuler:themeItem" with a colon is the problem.

}
}

McGuffin
August 5th, 2007, 05:58 PM
The : represents a namespace (in this case, the kuler namespace). Look up the section on namespaces here (http://www.senocular.com/flash/tutorials/as3withflashcs3/?page=4#e4x) for a pretty thorough rundown of the fun :)

joshchernoff
August 5th, 2007, 05:59 PM
thanks :rambo:

Reider
August 5th, 2007, 06:25 PM
var kuler:Namespace = myXML.namespace("kuler")

trace(myXML.channel.item[i].kuler::themeItem)