E4X:使用命名空间抓取节点? [英] E4X: grab nodes with namespaces?

查看:31
本文介绍了E4X:使用命名空间抓取节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习如何在 E4X 中使用命名空间处理 XML,所以基本上这就是我想学习的内容,比如我有一些这样的 XML:

I want to learn how to process XML with namespaces in E4X so basically here is what I want to learn, say I have some XML like this:

<rdf:RDF 
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns="http://purl.org/rss/1.0/">
    <rdf:item value="5"/>
    <item value="10"/>
</rdf:RDF>

如何将 <rdf:item/> 分配给一个名为 rdfItems 的 var,而将 <item/> 分配给一个var 称为 regItems?

How could I assign <rdf:item/> to a var called rdfItems and <item/> to a var called regItems?

谢谢!

推荐答案

我不确定这是否准确地回答了问题,但鉴于您的情况,以下代码检索两个值(给定xml"变量,在下面引用, 是一个 XML 对象,其中包含您提供的 XML 代码片段):

I'm not sure whether this answers the question exactly, but given your scenario, the following code retrieves both values (given the "xml" variable, referenced below, is an XML object containing the snippet of XML code you provided):

// Your "rdf" namespace
namespace rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
use namespace rdf;

// Your "reg" (i.e, default) namespace
namespace reg = "http://purl.org/rss/1.0/";
use namespace reg;

private function getYourValues():void
{               
    var rdfitems:String = xml.rdf::item.@value;
    var regitems:String = xml.reg::item.@value;
}

需要区分rdf"项和non-rdf"项,因为它们的元素名称在其他方面相同,因此声明了第二个命名空间以允许您独立检索每个项.希望对您有所帮助!

A distinction needs to be made between the "rdf" item and the "non-rdf" one, since their element names are otherwise identical, so the second namespace is declared to allow you to retrieve each item independently. Hope it helps!

这篇关于E4X:使用命名空间抓取节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆