菜鸟教程小白 发表于 2022-12-12 20:21:11

iphone - 如何使用 NSXMLParser 读取此 CDATA


                                            <p><p>我熟悉 NSXMLParser,我用它来读取一些 XML 行,但我对这些行有疑问:</p>

<pre><code>    &lt;item&gt;
    &lt;title&gt;Price Drop: AngerOfStick2(Games)&lt;/title&gt;
    &lt;link&gt;http://appshopper.com/games/angerofstick2&lt;/link&gt;
    &lt;category&gt;Games&lt;/category&gt;
    &lt;guid isPermaLink=&#34;false&#34;&gt;http://appshopper.com/games/angerofstick2-Wed, 18 Apr 2012 10:49:58 EDT-price&lt;/guid&gt;
    &lt;description&gt;&lt;![CDATA[
      &lt;img src=&#34;http://images.appshopper.com/icons/408/347359.png&#34; align=&#34;left&#34;/&gt;
      &lt;h3&gt;AngerOfStick2 1.1.6&lt;/h3&gt;&lt;br/&gt;
      &lt;b&gt;Device:&lt;/b&gt; iOS iPhone&lt;br /&gt;
      &lt;b&gt;Category:&lt;/b&gt; Games&lt;br /&gt;
      &lt;b&gt;Price:&lt;/b&gt; $.99 -&gt; Free, &lt;b&gt;Version:&lt;/b&gt; 1.1.6 (&lt;a href=&#34;/link/angerofstick2&#34;&gt;iTunes&lt;/a&gt;) &lt;br/&gt;&lt;br/&gt;
      &lt;img src=&#34;http://a1.mzstatic.com/us/r1000/106/Purple/v4/f7/91/f9/f791f91e-454f-9525-2ebc-9c341707d0ad/mza_5266557554023051353.640x960-75.jpg&#34; width=&#34;480&#34; align=&#34;right&#34;/&gt;
      &lt;b&gt;Description:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;
      Limited Time SALE! 50% OFF! Get it now and don’t miss out!============UPDATES INFO============= version 1.0.1 :-Game Center Support-RETINA Icon Supportversion 1.0.2 :- Doodle Runner ( Add New Mode )version 1.0.3 :- Survival Mode ( Add New Mode ) version 1.0.4 :- Jump Jump Mode ( Add New Mode ) version 1.0.6 :-Mulitiplayer Mode: 1 vs 1   ( Add New Mode )------Main Update Plan------=====================================User say :- &amp;quot; This is a wonderful game! It has a perfect balance of fast action-packed entertainment, and it is completely addicting! I would recommend this game to anyone! &amp;quot;- &amp;quot; Get this game! It&#39;s one of the best games I&#39;ve played for a while! GET THIS GAME! &amp;quot;- &amp;quot; This game is the beast so addicte to it I can&#39;t stop playing it. &amp;quot;- &amp;quot; This is a great game! Really REALLY entertaining when you get into the zone. 5 stars !!!!!!!!!!!!!!!!&amp;quot;- &amp;quot; Ohh yeaaaaaaaa oh yeaaaa oh yea! &amp;quot;Introduction:- Anger of stick 2nd Story -Unknown enemies in the city emerge and the hero continues to remove enemies with a variety of weapons, and helicopters and robots that can devastate all enemies at a time.Special Features: - Action : You can feel the realistic fighting action with 130 behaviors and Hero air combo action is added that can remove all enemies at one time.- Weapons: Enemies can be handled lightly by using helicopters and robots in the map, and weapons such as M1911, UZI, Granade Luncher, Spas_12, SG550, Remington_870, Flamethrower, Ray-gun, Mini-gun, Bat, and Sword.- Map: Cities, deserts and forests are configured in the map and the fighting action inside building is added.Tips:- When enemies come on the both sides, all enemies will be fallen down on seizing and throwing enemies back.- An infinite combo attack is available with Hero air combo.- Enemies can be handled by well-using robots and helicopters on the streets.- To avoid the attacks from guns and robots of enemies, button on the key to move to the left is necessary.Support Information: For additional support, please contact: E-mail : [email protected]&lt;br/&gt;&lt;br/&gt;&lt;b&gt;What&#39;s New&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Fixed some bug.&lt;br/&gt;&lt;br/&gt;
      &lt;a href=&#34;http://appshopper.com/games/angerofstick2&#34;&gt;AngerOfStick2&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
    ]]&gt;&lt;/description&gt;
    &lt;pubDate&gt;Wed, 18 Apr 2012 10:49:58 EDT&lt;/pubDate&gt;
    &lt;/item&gt;
</code></pre>

<p>如何从描述元素中获取 img src?</p>

<p>谢谢</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>使用这个方法...</p>

<pre><code>- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock
{
    NSString *someString = [ initWithData:CDATABlock encoding:NSUTF8StringEncoding];
// reparse the string to extract the img src attribute value...
}
</code></pre>

<p>希望这会有所帮助... :D</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 如何使用 NSXMLParser 读取此 CDATA,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/10214747/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/10214747/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 如何使用 NSXMLParser 读取此 CDATA