XML AS3选择图像URL命名空间值 [英] XML AS3 Selecting Image URL Namespace value
问题描述
var imgUrl:String = comicXML.children()。content。@ url;
与comicXML是url请求。跟踪单独的comicXML是否正常工作,并返回XML。也许有人可以给我一两个提示?
这是一个棘手的问题,部分原因是因为挂起并不是处理命名空间的基本XML处理。您会在< item>
中注意到,有一个标记< media:content url =blahblahblah/>
$ b $ media:make
content
媒体命名空间的一部分,它允许我们有两个同名的标记作为父标记的一部分,而不会与其他命名空间中同名的标记冲突。您可以看到< item>
同时包含< title>
和< ; media:title>
并且不会抱怨它。
您还会注意到,在根标记中有几个命名空间(媒体,原子和creativeCommons):
< rss xmlns:media =http:// search。 yahoo.com/mrss/
xmlns:atom =http://www.w3.org/2005/Atom
xmlns:creativeCommons =http://backend.userland.com/creativeCommonsRssModule
version =2.0>
要使用它们,您需要创建一个Namespace变量:
var myXML:XML = new XML(loader.data);
var media:Namespace = myXML.namespace(media);
现在我们已经创建了代表xmlns:media的媒体,我们可以访问任何标签与媒体:这样的代码前缀(注意::双冒号):
trace(myXML.channel。 。项[0] .media :: @内容URL);
我发现这些链接很有帮助第二个!):
http://lab.revoke.ca/2009/05/as3-xml-namespace/
Basically, for a project I am making a comic reader in flash with XML provided by a comic strip on deviantart. I'm only so far trying to figure out how to extract the url of an image within an item object, I think I'm mostly struggling with learning how the syntax is supposed to be. I've tried: Maybe someone can give me a hint or two? This is a tricky one, partly because the hangup isn't so much basic XML processing as it is dealing with namespaces. You'll notice within your That " You'll also notice, in your root tag, there are several namespaces (media, atom, and creativeCommons) defined with xmlns: To use them, you'll need to create a Namespace variable: Now that we've created media, which represents the xmlns:media, we can access any of the tags with the media: prefix with code like this (notice the :: double-colon):
I found these links to be helpful (especially the second one!): http://lab.revoke.ca/2009/05/as3-xml-namespace/ http://coursesweb.net/actionscript/xml-e4x-namespaces 这篇关于XML AS3选择图像URL命名空间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!var imgUrl:String = comicXML.children().content.@url;
with comicXML being the url request. Tracing comicXML alone Does work correctly and gives back the XML.<item>
, there is a tag <media:content url="blahblahblah" />
media:
" makes content
part of the media namespace, and it allows us to have two tags with the same name be part of a parent tag without conflicting with tags of the same name in other namespaces. You can see that <item>
has both a <title>
and a <media:title>
and doesn't complain about it.<rss xmlns:media="http://search.yahoo.com/mrss/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
version="2.0">
var myXML:XML = new XML( loader.data );
var media:Namespace = myXML.namespace("media");
trace(myXML.channel.item[0].media::content.@url);