[英]TouchXML elementsForName Not Working
I have a div
element in TouchXML, and I know for a fact that it contains an a
element which I need to access. 我在TouchXML中有一个
div
元素,并且我知道它包含一个我需要访问a
元素。 This is the element, which is declared as CXMLElement *element
in a for-in loop 这是元素,在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>
(Sorry about the formatting; I didn't write it) (很抱歉格式化;我没有写出来)
As you can see, there is an a
element (there's actually two) in this. 如您所见,其中有
a
元素(实际上有两个)。 However, when I attempt to access these elements using the following 但是,当我尝试使用以下方法访问这些元素时
NSArray *linkElements = [element elementsForName:@"a"];
linkElements
always contains 0 objects. linkElements
始终包含0个对象。 Why is TouchXML not filling linkElements
with the two a
elements? 为什么TouchXML没有用两个
a
元素填充linkElements
?
The elementsForName:
method only looks at the immediate child nodes of the element. elementsForName:
方法仅查看elementsForName:
的直接子节点。 It does not do a recursive descent. 它不进行递归下降。 In your posted code,
element
does not have any a
elements, just more div
child elements. 在你贴的代码,
element
没有任何a
元素,只是更div
子元素。 You need to write your own code to recursively traverse all of the child div
elements until you find all of the desired a
elements. 您需要编写自己的代码以递归地遍历所有子
div
元素,直到找到所需a
所有元素为止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.