在Flash中处理带有Namespace的XML

现在带Namespace的xml越来越多了,尤其是一些大网站的feed或者结构化数据。最近也在工作中遇到了一些类似的情况,这里记录一下处理的方法。

 // feed xml  

<feed xmlns="http://www.feed.com">
<title>Feed Title</title>
<content>
<source>
http://licenseserver2k4.roxionow.com/drm/acquirelicense.asmx
</source>
</content>
</feed>

获取节点信息的方法如下:

 var xml:XML = xmlSource;  

var ns:Namespace = xml.namespace();
var title:String = xml.ns::title;
var sourceURL:String = xml.ns::content.ns::source;

另外一个例子

 <rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' version='2.0'>  

<channel>
<atom:id>tag:blogger.com,1999:blog-</atom:id>
<lastBuildDate>Wed, 10 Sep 2008 19:07:53 +0000</lastBuildDate>
<title></title>
<description></description>
<link>asdfasdf.com/</link>
<managingEditor>noreply@blogger.com (Erik Loehfelm)</managingEditor>
<generator>Blogger</generator>
<openSearch:totalResults>9</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>25</openSearch:itemsPerPage>
<item>
<guid isPermaLink='false'>tag:blogger.com,1999:blog-</guid>
<pubDate>Wed, 10 Sep 2008 19:07:00 +0000</pubDate>
<atom:updated>2008-09-10T15:07:53.696-04:00</atom:updated>
<category domain='http://www.blogger.com/atom/ns#'>feature</category>
<title>People Singing</title>
<atom:summary>This is going to be a feature for the portal.v/atom:summary>
<link>asdfasdfasdf.html</link>
<enclosure type='image/jpeg' url='http://msnbcmedia.msn.com/j/msnbc/Components/Slideshows/_production/ss-080522-idolfinale/ss-080522-idolfinale-09.hmedium.jpg' length='0'/>
<author>noreply@blogger.com (Erik Loehfelm)</author>
</item>
</channel>
</rss>

获取内容的方法如下:

 var ns:Namespace = theXML.namespace();  

for each (var property:XML in theXML..item)
{
var atom:Namespace = property.namespace("atom");
var fVO:FeatureVO = new FeatureVO();
fVO.pubDate = property.pubDate;
fVO.updated = property.atom::updated;
fVO.category = property.category;
fVO.title = property.title;
fVO.summary = property.atom::summary;
fVO.link = property.link;
fVO.enclosure = property.enclosure.@url;
fVO.xmlData = property;
model.featuresArray.push(fVO);
}

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s