解析 AS3 XML 对象
我从 ASP.NET 获取一个对象,在跟踪 XML 时,如下所示:
var xml:XML = new XML(event.message.body);
trace(xml);
我得到以下输出:
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://localhost:49329/">
<string>One</string>
<string>Two</string>
<string>Three</string>
</ArrayOfString>
我试图迭代该结构以提取字符串,但无济于事。我正在使用以下代码:
for each(var item:Object in xml.children())
{
MonsterDebugger.trace(this, item.toString());
}
...我知道这并不完全有效。它现在可以工作,但是有一种方法可以使用 @ 符号获取具有某些语法的字符串。
有人可以建议吗?
I am getting an object back from ASP.NET, and when tracing the XML it as follows:
var xml:XML = new XML(event.message.body);
trace(xml);
I get the following output:
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://localhost:49329/">
<string>One</string>
<string>Two</string>
<string>Three</string>
</ArrayOfString>
I am trying to iterate the structure to get the strings extracted, but to no avail. I am using the following code:
for each(var item:Object in xml.children())
{
MonsterDebugger.trace(this, item.toString());
}
...and I know this is not entirely effective. It works now, but there is a way to get the strings with some syntax using the @ sign.
Can anyone please advise?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你已经差不多明白了。应该能够像这样编写相同的循环:
看看这些 e4x 文档,这些是针对 Flex 的,但这一切都适用,因为它只是 AS3。正如您所看到的,很多此类内容的文档状态都有点不稳定:)
You've pretty much got it. Should be able to write the same loop like so:
Take a look at these e4x docs, these are for Flex, but it all applies because it's just AS3. As you can see the state of documentation on a lot of this stuff is a little flaky :)
您还必须照顾命名空间:
You have to take care of the Namespace too:
您可以阅读我对 AS3 - Deepest XML Elements 的回答
通过使用 SimpleXML,您可以以易于使用的方式解析 XML。
You can read my answer to AS3 - Deepest XML Elements
By using SimpleXML you can parse your XML in an easy to use manner.