解析 AS3 XML 对象

发布于 2024-08-11 07:31:40 字数 695 浏览 6 评论 0原文

我从 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 技术交流群。

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

发布评论

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

评论(3

︶ ̄淡然 2024-08-18 07:31:40

你已经差不多明白了。应该能够像这样编写相同的循环:

for each( var el:XML in xml.string ) {
  trace( el.toString() );
}

看看这些 e4x 文档,这些是针对 Flex 的,但这一切都适用,因为它只是 AS3。正如您所看到的,很多此类内容的文档状态都有点不稳定:)

You've pretty much got it. Should be able to write the same loop like so:

for each( var el:XML in xml.string ) {
  trace( el.toString() );
}

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

将军与妓 2024-08-18 07:31:40
<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>

您还必须照顾命名空间:

var ns:Namespace = new Namespace("http://localhost:49329/");
var strings:XMLList = xml.ns::string;
for each(var str:XML in strings)
  trace(str.text());
<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>

You have to take care of the Namespace too:

var ns:Namespace = new Namespace("http://localhost:49329/");
var strings:XMLList = xml.ns::string;
for each(var str:XML in strings)
  trace(str.text());
你怎么敢 2024-08-18 07:31:40

您可以阅读我对 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.

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