ios - 如何在 iOS 中解析这种类型的 XML 数据?

标签 ios objective-c xml-parsing

如何解析 enclosure_details 属性?这是我的 XML 输出。

<enclosure>
                    <enclosure_details url="http://cdn..com/media/gallery/p18gmcacuj1o4n1572b1m1qnel1c6.jpg" length="12345" type="image/jpeg" title=<![CDATA[]]> description=<![CDATA[&lt;p&gt;Mergers and acquisitions have gained steam in early 2014. Here is a rundown of the whole-bank deals, shedding of noncore businesses and swapping of securities so far this year.&lt;/P&gt;&lt;P align=&quot;right&quot;&gt;&lt;em&gt;Image: Thinkstock&lt;/em&gt;&lt;/p&gt;]]> />
                    <enclosure_details url="http://cdn..com/media/gallery/p18gmcacuj1527me8acrk2r7td7.jpg" length="12345" type="image/jpeg" title=<![CDATA[Carolina Domino Effect?]]> description=<![CDATA[&lt;p&gt;VantageSouth in Raleigh, N.C., and Yadkin Financial in Elkin, N.C., announced plans in late January for &lt;a href=&quot;http://www..com/issues/179_18/vantagesouth-yadkin-deal-could-spur-meaningful-ma-in-north-carolina-1065227-1.html&quot;&gt;a $300 million merger&lt;/a&gt;. VantageSouth CEO Scott Custer will lead the bank. The MOE is expected to force other North Carolina banks to decide whether to become buyers or sellers.&lt;/P&gt;&lt;P align=&quot;right&quot;&gt;&lt;em&gt;Bloomberg News&lt;/em&gt;&lt;/p&gt;]]> />
                    <enclosure_details url="http://cdn..com/media/gallery/p18gmcacuj332qvhj7c1qbucn98.jpg" length="12345" type="image/jpeg" title=<![CDATA[Cost-Cutting Focus]]> description=<![CDATA[&lt;p&gt;ConnectOne in Englewood, N.J., is merging with Center Bancorp in Union, N.J., in &lt;a href=&quot;http://www..com/video/connectone-ceo-explains-banks-merger-with-center-of-nj1065072-1.html&quot;&gt;another MOE-like deal&lt;/a&gt; that would create a $3 billion-asset bank and is meant to produce $7 million in annual cost savings. Frank Sorrentino of ConnectOne will become the CEO.&lt;/p&gt;]]> />

最佳答案

尝试 iOS 版 NSXMLParser:https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSXMLParser_Class/Reference/Reference.html

你在这里有一个教程:http://iphonebyradix.blogspot.com/2011/08/parsing-xml-using-nsxmlparser.html

此委托(delegate)方法为您获取标签内的字符串

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
}

此方法为您获取案例中的属性 enclosure_details 中的 url

- (void)parser:(NSXMLParser *)parser foundAttributeDeclarationWithName:(NSString *)attributeName forElement:(NSString *)elementName type:(NSString *)type defaultValue:(NSString *)defaultValue;

关于ios - 如何在 iOS 中解析这种类型的 XML 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21908131/

相关文章:

ios - 如何在不更改推送负载的情况下更改 iOS 远程通知的声音

c# - 如何为 XML 创建 XPath?

ios - -timeIntervalSinceNow 的 EXC_BAD_ACCESS 错误

ios - pushRegistry :didUpdate:pushCredentials not being called

iphone - 从适合一定宽度的字符串中提取字符串

xml - 与将 <complexType> 从一个 XSD 扩展到另一个 XSD 相关的查询

android - import org.w3c.dom.Document 与 android 中的另一个 import 语句冲突

ios - 尺寸等级和加号电话

ios - 与其他应用程序共享应用程序商店 URL

objective-c - 将对象添加到 NSMutableArray 属性