E4X:抓取具有命名空间的节点? [英] E4X: grab nodes with namespaces?

查看:32
本文介绍了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/> 分配给一个名为 rdfItems 的 varvar 称为 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"项目和非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天全站免登陆