E4X / AS3:如何访问一个节点,其名称中的破折号 [英] e4x / as3: How to access a node with a dash in its name

查看:96
本文介绍了E4X / AS3:如何访问一个节点,其名称中的破折号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AS3的E4X的实现似乎并不能够处理已经在他们破折号节点名称。该MusicBrainz的API返回的XML与名为艺术家名单的一个节点,我似乎无法得到它让我访问节点。

http://musicbrainz.org/ws样本?/ 1 /艺术家/类型= XML和放大器;名称=博士%20dog

 <元数据的xmlns =htt​​p://musicbrainz.org/ns/mmd-1.0#的xmlns:EXT =htt​​p://musicbrainz.org/ns/ext- 1.0#>
    &所述;艺术家表偏移=0计数=1090>
        <艺术类=组ID =e9aed5e5-ed35-4244-872e-194862290295分机:得分=100>
        < /艺术家>
    < /艺术家列表>
< /元>
 

如果我尝试访问它,像这样 myXml.artist名单我得到的编译时错误:

 错误:未定义的属性列表访问。
 

有人知道一种解决方法吗?

- 编辑:完整的源 -

 变种L:的URLLoader =新的URLLoader();
    l.load(新的URLRequest(http://musicbrainz.org/ws/1/artist/?type=xml&name=dr%20dog));
    l.addEventListener(引发Event.COMPLETE,功能(五:事件){
        VAR与myXML:XML = XML(e.target.data);
        跟踪(myXml.artist名单)
    });
 

解决方案

补充工作示例使用两种语法: HTTP ://wonderfl.net/c/hyuG

您可以使用与myXML [我的领域] 符号让你的领域,因为你的XML具有命名空间在里面你要指定它,要做到这一点的一个方法是:

  VAR NS:命名空间=新的命名空间(http://musicbrainz.org/ns/mmd-1.0#)
跟踪(myXml.ns :: [艺术家名单])
 

另一种方法是设置默认的命名空间:

  VAR NS:命名空间=新的命名空间(http://musicbrainz.org/ns/mmd-1.0#)
默认XML命名空间= NS
跟踪(XML [艺术家名单])
 

the e4x implementation in as3 doesn't seem to be able to handle node names that have dashes in them. The musicbrainz api returns xml with a node named artist-list and i can't seem to get it to let me access the node.

sample from http://musicbrainz.org/ws/1/artist/?type=xml&name=dr%20dog :

<metadata xmlns="http://musicbrainz.org/ns/mmd-1.0#" xmlns:ext="http://musicbrainz.org/ns/ext-1.0#">
    <artist-list offset="0" count="1090">
        <artist type="Group" id="e9aed5e5-ed35-4244-872e-194862290295" ext:score="100">
        </artist>
    </artist-list>
</metadata>

If I try to access it like so myXml.artist-list i get the compile time error:

Error: Access of undefined property list.

Anybody know of a workaround?

--Edit: full source--

var l:URLLoader = new URLLoader();
    l.load(new URLRequest("http://musicbrainz.org/ws/1/artist/?type=xml&name=dr%20dog"));
    l.addEventListener(Event.COMPLETE, function(e:Event) {
        var myXml:XML = XML(e.target.data);
        trace(myXml.artist-list)
    });

解决方案

Added a working sample using the two syntaxes : http://wonderfl.net/c/hyuG

You can use myXml["my field"] notation to get your field, as your xml have namespace in it you have to specify it, one way to do this is:

var ns:Namespace=new Namespace("http://musicbrainz.org/ns/mmd-1.0#")
trace(myXml.ns::["artist-list"])

another way is to set the default namespace:

var ns:Namespace=new Namespace("http://musicbrainz.org/ns/mmd-1.0#")
default xml namespace=ns
trace(xml["artist-list"])

这篇关于E4X / AS3:如何访问一个节点,其名称中的破折号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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