Actionscript 3 E4X 处理 XML 中的命名空间值

发布于 2024-09-05 04:37:24 字数 136 浏览 5 评论 0 原文

我正在使用 Action script 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?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月如刀 2024-09-12 04:37:24

这些是 XML 命名空间,使用起来很麻烦。请查看有关使用 XML 命名空间的 Adob​​e 文档。

基本上,您必须获取名称空间:

var mmsNS:Namespace = message.namespace("mms");

// alternatively for nested namespaces:

var mmsNS:Namespace = new Namespace("mms", " ... url of namespace ... ");

然后当您想要获取它所应用到的节点时使用它:

var data:XML = message.@mmsNS::Results;

如果所有 xml 都位于特定名称空间中,则快捷方式是设置默认名称空间:

default xml namespace = mmsNs;

编辑:< /strong> 您尝试访问的 XML 命名空间必须在 XML 片段中声明:

<root xmlns:mms="http://example.com/mms">
    <mms:someNode someAttr="someVal" />
</root>

查看 w3c 文档中的 XML 命名空间 确保您的文档格式良好(甚至可以通过验证器传递它)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文