TouchXML elementsForName 不工作
TouchXML elementsForName Not Working
我在 TouchXML 中有一个 div
元素,我知道它包含一个我需要访问的 a
元素。这是在 for-in 循环
中声明为 CXMLElement *element
的元素
<div id="song_html" class="show3">
<div class="left">
<!-- info mp3 here -->
128 kbps<br/>2:35<br/>2.36 mb
</div>
<div id="right_song">
<div style="font-size:15px;"><b>The Doors - The Crystal Ship mp3</b></div>
<div style="clear:both;"/>
<div style="float:left;">
<div style="float:left; height:27px; font-size:13px; padding-top:2px;">
<div style="float:left;"><a href="http://member.jinbo.net/renegade/music/The Doors-03.The Crystal Ship.mp3" rel="nofollow" target="_blank" style="color:green;">Download</a></div>
<div style="margin-left:8px; float:left; width:27px; text-align:center;"><a href="javascript:void(0)" onclick="showPlayer_new(14851327, 'a89d3a80a719b6c91a4c441f879685e1c8647140', 'the+doors', 'the+crystal+ship')" rel="nofollow" id="lk14851327" class="play_now">Play</a></div>
<!-- New ad start -->
<script><![CDATA[
var id_array = ["newad14851327"]; window.onload = function(){
var i = 0;
for(i=0; i < id_array.length; i++){
var tgt = document.getElementById(id_array[i]).href; document.getElementById(id_array[i]).href = ""; document.getElementById(id_array[i]).onclick = function(){
window.location.href= tgt;
return false;
};
} }
]]>
</script><!-- New ad end -->
<div style="margin-left:8px; float:left;"><a href="http://ads.ad-center.com/offer?prod=91&ref=4989201&q=The+Doors+-+The+Crystal+Ship" rel="nofollow" target="_blank" style="color:red;" id="newad14851327">Download Album</a></div>
<!-- ToneFuse Start -->
<script><![CDATA[ (function(id) {
console.log("tonefuse id:"+id);
document.write('<div style="margin-left:8px; float:left; color:red;" id="'+id+'">]]>
</script>
</div>
');
tfp_multi_ad_slots = window.tfp_multi_ad_slots || [];
tfp_multi_ad_slots.push(id);
window.tfpWriteMultiAd && tfpWriteMultiAd();
})(("tfp_multi_"+Math.random()).replace(".",""));
<!-- ToneFuse End -->
<div style="clear:both;"/>
</div>
<div id="player14851327" style="float:left; margin-left:10px;" class="player"/>
</div>
<div style="clear:both;"/>
</div>
(抱歉格式问题;我没有写)
如您所见,其中有一个 a
元素(实际上有两个)。但是,当我尝试使用以下
访问这些元素时
NSArray *linkElements = [element elementsForName:@"a"];
linkElements
始终包含 0 个对象。为什么 TouchXML 没有用两个 a
元素填充 linkElements
?
elementsForName:
方法只查看元素的直接子节点。它不执行递归下降。在您发布的代码中,element
没有任何 a
元素,只有更多的 div
子元素。您需要编写自己的代码来递归遍历所有子 div
元素,直到找到所有需要的 a
元素。
我在 TouchXML 中有一个 div
元素,我知道它包含一个我需要访问的 a
元素。这是在 for-in 循环
CXMLElement *element
的元素
<div id="song_html" class="show3">
<div class="left">
<!-- info mp3 here -->
128 kbps<br/>2:35<br/>2.36 mb
</div>
<div id="right_song">
<div style="font-size:15px;"><b>The Doors - The Crystal Ship mp3</b></div>
<div style="clear:both;"/>
<div style="float:left;">
<div style="float:left; height:27px; font-size:13px; padding-top:2px;">
<div style="float:left;"><a href="http://member.jinbo.net/renegade/music/The Doors-03.The Crystal Ship.mp3" rel="nofollow" target="_blank" style="color:green;">Download</a></div>
<div style="margin-left:8px; float:left; width:27px; text-align:center;"><a href="javascript:void(0)" onclick="showPlayer_new(14851327, 'a89d3a80a719b6c91a4c441f879685e1c8647140', 'the+doors', 'the+crystal+ship')" rel="nofollow" id="lk14851327" class="play_now">Play</a></div>
<!-- New ad start -->
<script><![CDATA[
var id_array = ["newad14851327"]; window.onload = function(){
var i = 0;
for(i=0; i < id_array.length; i++){
var tgt = document.getElementById(id_array[i]).href; document.getElementById(id_array[i]).href = ""; document.getElementById(id_array[i]).onclick = function(){
window.location.href= tgt;
return false;
};
} }
]]>
</script><!-- New ad end -->
<div style="margin-left:8px; float:left;"><a href="http://ads.ad-center.com/offer?prod=91&ref=4989201&q=The+Doors+-+The+Crystal+Ship" rel="nofollow" target="_blank" style="color:red;" id="newad14851327">Download Album</a></div>
<!-- ToneFuse Start -->
<script><![CDATA[ (function(id) {
console.log("tonefuse id:"+id);
document.write('<div style="margin-left:8px; float:left; color:red;" id="'+id+'">]]>
</script>
</div>
');
tfp_multi_ad_slots = window.tfp_multi_ad_slots || [];
tfp_multi_ad_slots.push(id);
window.tfpWriteMultiAd && tfpWriteMultiAd();
})(("tfp_multi_"+Math.random()).replace(".",""));
<!-- ToneFuse End -->
<div style="clear:both;"/>
</div>
<div id="player14851327" style="float:left; margin-left:10px;" class="player"/>
</div>
<div style="clear:both;"/>
</div>
(抱歉格式问题;我没有写)
如您所见,其中有一个 a
元素(实际上有两个)。但是,当我尝试使用以下
NSArray *linkElements = [element elementsForName:@"a"];
linkElements
始终包含 0 个对象。为什么 TouchXML 没有用两个 a
元素填充 linkElements
?
elementsForName:
方法只查看元素的直接子节点。它不执行递归下降。在您发布的代码中,element
没有任何 a
元素,只有更多的 div
子元素。您需要编写自己的代码来递归遍历所有子 div
元素,直到找到所有需要的 a
元素。