Actionscript 3 E4X使用XML中的名称空间值 [英] Actionscript 3 E4X working with namespace values in XML
问题描述
我正在使用动作脚本3构建应用程序.我正在从Web检索一些XML,但是节点名称是mms:Image mms:Results等,因为我不希望看到半冒号,所以我的动作脚本编译器抛出了错误.在节点名称中.如何访问节点?
I am building an application using Action script 3 I am retrieving some XML from the web however the node names are mms:Image mms:Results etc my action script compiler is throwing an error becuase it is not expecting to see the semi colon in the node name. How to I access the nodes?
谢谢
推荐答案
这些都是XML名称空间,使用起来很麻烦.在使用XML名称空间上查看Adobe文档.
Those are XML namespaces and they can be a pain to use. Have a look at the Adobe documentation on Using XML namespaces.
基本上,您必须获取名称空间:
Basically you have to get the namespace:
var mmsNS:Namespace = message.namespace("mms");
// alternatively for nested namespaces:
var mmsNS:Namespace = new Namespace("mms", " ... url of namespace ... ");
然后在要获取其应用于的节点时使用它:
And then use it when you want to get the nodes that it is applied to:
var data:XML = message.@mmsNS::Results;
如果您的所有xml都位于特定的命名空间中,则快捷方式是设置默认的命名空间:
A shortcut if all of your xml is in a particular namespace is to set the default namespace:
default xml namespace = mmsNs;
编辑:必须在XML片段内声明要访问的XML名称空间:
edit: The XML namespace you are trying to access must be declared within the XML fragment:
<root xmlns:mms="http://example.com/mms">
<mms:someNode someAttr="someVal" />
</root>
查看 XML命名空间的w3c文档,以确保您的文档格式正确(甚至可以通过验证程序).
Have a look at the w3c docs for XML Namespaces to ensure your document is well-formed (maybe even pass it through a validator).
这篇关于Actionscript 3 E4X使用XML中的名称空间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!