getting value from a list
I have a xml that looks like this:
<?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开发者_JAVA百科&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>
How would i be able to get the values from the <a>
tags that are inside the <li>
tags?
What you can do if your <content>
is well formed , is to transform it in XML
and then use e4x
to query the informations you wanted.
You have one more thing to be carefull is that your XML
contains namespace
so to get the content node you have to take care of that. I suggest you reading the good post about XML here for example.
So the content
node is inside the entry
node that have also a namespace
, but as it 's the same as the root node we can reuse the same 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);
精彩评论