Actionscript 3 E4X working with namespace values in XML

三世轮回 提交于 2019-12-02 04:26:32
James Fassett

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;

A shortcut if all of your xml is in a particular namespace is to set the default namespace:

default xml namespace = mmsNs;

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>

Have a look at the w3c docs for XML Namespaces to ensure your document is well-formed (maybe even pass it through a validator).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!