XML AS3选择图像URL命名空间值 [英] XML AS3 Selecting Image URL Namespace value

查看:175
本文介绍了XML AS3选择图像URL命名空间值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,对于一个项目,我正在使用XML提供的一个漫画阅读器。在deviantart上的漫画。我只是想了解如何提取项目对象中的图像的网址,我想我主要是在学习语法应该如何努力。我试过了: 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: var imgUrl:String = comicXML.children().content.@url; with comicXML being the url request. Tracing comicXML alone Does work correctly and gives back the XML.

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 <item>, there is a tag <media:content url="blahblahblah" />

That "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.

You'll also notice, in your root tag, there are several namespaces (media, atom, and creativeCommons) defined with xmlns:

<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">

To use them, you'll need to create a Namespace variable:

var myXML:XML = new XML( loader.data );
var media:Namespace = myXML.namespace("media");

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):

trace(myXML.channel.item[0].media::content.@url);


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆