E4X:与命名空间抢节点?节点、空间、E4X

2023-09-08 12:14:27 作者:一身祖宗味儿

我要学习如何处理XML名称空间的E4X所以基本上这里就是我想学习,说我有一些像这样的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>

我怎么可以指定&LT; RDF:项目/&GT; 来一个名为VAR rdfItems 和&LT;项目/&GT; 来一个名为VAR regItems

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

谢谢!

推荐答案

我不知道这是否正是回答了这个问题,但由于您的方案,下面的code检索两个值(给出的XML变量下面引用的,是一个包含XML $ C $的片段c您提供)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!

 
精彩推荐
图片推荐