xml在iOS上解析疑惑

时间:2011-07-26 13:49:33

标签: ios xml-parsing

<category name="Politics"> 
<item> 
<oid>2754</oid> 
<title>²XÉÄá çµÞYd·Øí ®¢ÉßÎÞV ÈÞæ{ øÞ¼ßÕÏíAá¢</title> 
<thumbImage>http://122.248.234.55/v3/repository/images/news/telangana._thuthumb_2754.jpg</thumbImage> 
<shortDescription>æÄÜCÞÈ çζÜÏßW ÈßKáU ²XÉÄí ®¢ÉßÎÞV ÈÞæ{ øÞ¼ßØÎVMßAá¢.</shortDescription>
</item> 
<item> 
<oid>2753</oid> 
<title>ÄáGá ÕÞBáKÕøæˆKí Õß.®ØßçÈÞ¿á ¼ÏøÞ¼X</title> 
<thumbImage>http://122.248.234.55/v3/repository/images/news/MV-Jayarajan_thuthumb_2753.jpg</thumbImage> 
<shortDescription>Éß¼ß dÉçÕÖÈJßæa µÞøcJßW 50:50 ÉÞÜßAÞX µÝßEßæˆKá ¼ÏøÞ¼X ØNÄß‚á.</shortDescription>
</item> 
<item> 
<oid>2751</oid> 
<title>ÕÜßÏ ØìµøcB{ÞÏçMÞZ ضÞÕßæÈ ØßÉß®¢ ÎùKá</title> 
<thumbImage>http://122.248.234.55/v3/repository/images/news/saghavu_thuthumb_2751.jpg</thumbImage> 
<shortDescription>Éß. µã×íà ÉßU ØVMÆ¢ÖÈçÎxá Îøß‚ Õà¿í ÎcâØßÏÎÞAß Ø¢øfßAáæÎK ÕÞ·íÆÞÈÎÞÃá ¼Üçø~ÏÞµáKÄí.</shortDescription>
</item> 
</category> 
<category name="Sports"> 
<item> 
<oid>2750</oid> 
<title>dÖàÖÞLí ÕàIᢠ¿à¢ §LcÏßW</title> 
<thumbImage>http://122.248.234.55/v3/repository/images/news/sreesan_thuthumb_2750.jpg</thumbImage> 
<shortDescription>§¢±Ií Éøc¿ÈJßÈáU §LcX dµßAxí ¿àÎßW ÎÜÏÞ{ß ÄÞø¢ dÖàÖÞLá¢</shortDescription>
</item> 
<item> 
<oid>2749</oid> 
<title>µbßçxÞÕ çÈ¿ß</title> 
<thumbImage>http://122.248.234.55/v3/repository/images/news/sp-kvitova_thuthumb_2749.jpg</thumbImage> 
<shortDescription>ÎøßÏ ×ùçMÞÕæÏ ÉùMß‚ µbßçxÞÕÏÞÃí ÉáÄßÏ ÕßOßZÁX ÕÈßÄÞ ºÞ¢ÉcX</shortDescription>
</item> 
<item> 
<oid>2748</oid> 
<title>¥V¼aàÈ, ÙÞÕâ øfæMGá!</title> 
<thumbImage>http://122.248.234.55/v3/repository/images/news/sp-backheel_thuthumb_2748.jpg</thumbImage> 
<shortDescription>çµÞM ¥çÎøßA ¥V¼aàÈÏáæ¿ ¿âVÃæÎaÞµáæÎK æÉÞÄá ÇÞøÃÏÞÃí ©Æí¸Þ¿È ÎWØøJßW ÉÞ{ßÏÄí.</shortDescription>
</item> 
</category> 

如何解析这个xml文件?有两类“政治”和“体育”。我如何在解析器didStartElement和解析器didEndElement中定义它。我曾尝试过,但我无法将类别及其值分开。

2 个答案:

答案 0 :(得分:1)

您可以使用NSXMLParser

这是一个简单易用的API,here is an example.

或者您也可以在给定NSMutableData的情况下尝试使用CoreFoundation。 here is the example

Just Cocoa? So try this

答案 1 :(得分:-1)