从列表中获取价值

时间:2010-12-01 14:21:30

标签: actionscript-3

我有一个看起来像这样的xml:

    <?xml version="1.0" encoding="UTF-8"?>

<feed xmlns="http://www.w3.org/2005/Atom" version="1.0" xml:lang="en">
<title type="text">Google Hot Trends</title>
<subtitle type="text">What are people searching for on Google today?</subtitle>
<id>http://www.google.com/trends/hottrends/atom/hourly,2007-08</id>
<link href="http://www.google.com/trends/hottrends/atom/hourly" rel="self"/>
<updated>2010-12-01T14:03:30Z</updated>
<entry xmlns="http://www.w3.org/2005/Atom">
<id>2010-12-01T14:03:30Z</id>
<title type="text"><![CDATA[rosa parks, adam levine girlfriend, meet the famous, ...]]></title>

<content type="html"><![CDATA[<ol>
<li><span class="Mild up2"><a href="http://www.google.com/trends/hottrends?q=rosa+parks&date=2010-12-1&sa=X">rosa parks</a></span></li>
<li><span class="Mild down1"><a href="http://www.google.com/trends/hottrends?q=adam+levine+girlfriend&date=2010-12-1&sa=X">adam levine girlfriend</a></span></li>
<li><span class="Mild down1"><a href="http://www.google.com/trends/hottrends?q=meet+the+famous&date=2010-12-1&sa=X">meet the famous</a></span></li>
<li><span class="Mild equal"><a href="http://www.google.com/trends/hottrends?q=sons+of+anarchy+season+4&date=2010-12-1&sa=X">sons of anarchy season 4</a></span></li>
<li><span class="Mild equal"><a href="http://www.google.com/trends/hottrends?q=victoria+secret+angels&date=2010-12-1&sa=X">victoria secret angels</a></span></li>
<li><span class="Mild up5"><a href="http://www.google.com/trends/hottrends?q=happy+hanukkah&date=2010-12-1&sa=X">happy hanukkah</a></span></li>
<li><span class="Mild down1"><a href="http://www.google.com/trends/hottrends?q=katy+perry+victoria+secret+fashion+show&date=2010-12-1&sa=X">katy perry victoria secret fashion show</a></span></li>
<li><span class="Mild down1"><a href="http://www.google.com/trends/hottrends?q=married+to+the+mob+clothing&date=2010-12-1&sa=X">married to the mob clothing</a></span></li>
<li><span class="Mild down1"><a href="http://www.google.com/trends/hottrends?q=victoria+secret+models+names+and+pictures&date=2010-12-1&sa=X">victoria secret models names and pictures</a></span></li>
<li><span class="Mild equal"><a href="http://www.google.com/trends/hottrends?q=world+aids+day+2010&date=2010-12-1&sa=X">world aids day 2010</a></span></li>
<li><span class="Mild up6"><a href="http://www.google.com/trends/hottrends?q=shahla+jahed&date=2010-12-1&sa=X">shahla jahed</a></span></li>
<li><span class="Mild equal"><a href="http://www.google.com/trends/hottrends?q=interpol&date=2010-12-1&sa=X">interpol</a></span></li>
<li><span class="Mild up18"><a href="http://www.google.com/trends/hottrends?q=wallis+simpson&date=2010-12-1&sa=X">wallis simpson</a></span></li>
<li><span class="Mild up46"><a href="http://www.google.com/trends/hottrends?q=chanukah&date=2010-12-1&sa=X">chanukah</a></span></li>
<li><span class="Mild new"><a href="http://www.google.com/trends/hottrends?q=hiv+symptoms&date=2010-12-1&sa=X">hiv symptoms</a></span></li>
<li><span class="Mild up6"><a href="http://www.google.com/trends/hottrends?q=santa+tracker&date=2010-12-1&sa=X">santa tracker</a></span></li>
<li><span class="Mild down8"><a href="http://www.google.com/trends/hottrends?q=vs+fashion+show+2010&date=2010-12-1&sa=X">vs fashion show 2010</a></span></li>
<li><span class="Mild down3"><a href="http://www.google.com/trends/hottrends?q=advent+calendar&date=2010-12-1&sa=X">advent calendar</a></span></li>
<li><span class="Mild up8"><a href="http://www.google.com/trends/hottrends?q=december+1&date=2010-12-1&sa=X">december 1</a></span></li>
<li><span class="Mild up19"><a href="http://www.google.com/trends/hottrends?q=aids+ribbon&date=2010-12-1&sa=X">aids ribbon</a></span></li>
</ol>
]]></content></entry></feed>

如何从<a>代码中的<li>代码中获取值?

1 个答案:

答案 0 :(得分:2)

如果<content>格式正确,您可以执行的操作是将其转换为XML,然后使用e4x查询您想要的信息。

您需要注意的另一件事是XML包含namespace,以便获取内容节点,您必须要处理它。我建议你阅读关于XML here的好帖子。

因此content节点位于entry节点内且还有namespace,但由于它与根节点相同,我们可以重用相同的namespace var xml:XML=<feed xmlns="http://www.w3.org/2005/Atom" version="1.0" xml:lang="en"> <title type="text">Google Hot Trends</title> <subtitle type="text">What are people searching for on Google today?</subtitle> <id>http://www.google.com/trends/hottrends/atom/hourly,2007-08</id> <link href="http://www.google.com/trends/hottrends/atom/hourly" rel="self"/> <updated>2010-12-01T14:03:30Z</updated> <entry xmlns="http://www.w3.org/2005/Atom"> <id>2010-12-01T14:03:30Z</id> <title type="text"><![CDATA[rosa parks, adam levine girlfriend, meet the famous, ...]]></title> <content type="html"><![CDATA[<ol> <li><span class="Mild up2"><a href="http://www.google.com/trends/hottrends?q=rosa+parks&date=2010-12-1&sa=X">rosa parks</a></span></li> <li><span class="Mild down1"><a href="http://www.google.com/trends/hottrends?q=adam+levine+girlfriend&date=2010-12-1&sa=X">adam levine girlfriend</a></span></li> <li><span class="Mild down1"><a href="http://www.google.com/trends/hottrends?q=meet+the+famous&date=2010-12-1&sa=X">meet the famous</a></span></li> <li><span class="Mild equal"><a href="http://www.google.com/trends/hottrends?q=sons+of+anarchy+season+4&date=2010-12-1&sa=X">sons of anarchy season 4</a></span></li> <li><span class="Mild equal"><a href="http://www.google.com/trends/hottrends?q=victoria+secret+angels&date=2010-12-1&sa=X">victoria secret angels</a></span></li> <li><span class="Mild up5"><a href="http://www.google.com/trends/hottrends?q=happy+hanukkah&date=2010-12-1&sa=X">happy hanukkah</a></span></li> <li><span class="Mild down1"><a href="http://www.google.com/trends/hottrends?q=katy+perry+victoria+secret+fashion+show&date=2010-12-1&sa=X">katy perry victoria secret fashion show</a></span></li> <li><span class="Mild down1"><a href="http://www.google.com/trends/hottrends?q=married+to+the+mob+clothing&date=2010-12-1&sa=X">married to the mob clothing</a></span></li> <li><span class="Mild down1"><a href="http://www.google.com/trends/hottrends?q=victoria+secret+models+names+and+pictures&date=2010-12-1&sa=X">victoria secret models names and pictures</a></span></li> <li><span class="Mild equal"><a href="http://www.google.com/trends/hottrends?q=world+aids+day+2010&date=2010-12-1&sa=X">world aids day 2010</a></span></li> <li><span class="Mild up6"><a href="http://www.google.com/trends/hottrends?q=shahla+jahed&date=2010-12-1&sa=X">shahla jahed</a></span></li> <li><span class="Mild equal"><a href="http://www.google.com/trends/hottrends?q=interpol&date=2010-12-1&sa=X">interpol</a></span></li> <li><span class="Mild up18"><a href="http://www.google.com/trends/hottrends?q=wallis+simpson&date=2010-12-1&sa=X">wallis simpson</a></span></li> <li><span class="Mild up46"><a href="http://www.google.com/trends/hottrends?q=chanukah&date=2010-12-1&sa=X">chanukah</a></span></li> <li><span class="Mild new"><a href="http://www.google.com/trends/hottrends?q=hiv+symptoms&date=2010-12-1&sa=X">hiv symptoms</a></span></li> <li><span class="Mild up6"><a href="http://www.google.com/trends/hottrends?q=santa+tracker&date=2010-12-1&sa=X">santa tracker</a></span></li> <li><span class="Mild down8"><a href="http://www.google.com/trends/hottrends?q=vs+fashion+show+2010&date=2010-12-1&sa=X">vs fashion show 2010</a></span></li> <li><span class="Mild down3"><a href="http://www.google.com/trends/hottrends?q=advent+calendar&date=2010-12-1&sa=X">advent calendar</a></span></li> <li><span class="Mild up8"><a href="http://www.google.com/trends/hottrends?q=december+1&date=2010-12-1&sa=X">december 1</a></span></li> <li><span class="Mild up19"><a href="http://www.google.com/trends/hottrends?q=aids+ribbon&date=2010-12-1&sa=X">aids ribbon</a></span></li> </ol> ]]></content></entry></feed>; // get the current namespace from the XML var ns:Namespace = xml.namespace(); // get and create a new XML from the content node using the previous namespace var contentXML:XML = new XML(xml.ns::entry.ns::content.toString()); // get all the a node var anchors:XMLList = contentXML.li.span.a; // now do what you want with values for each (var anchor:XML in anchors) trace(anchor.@href); 节点}:

{{1}}