How do I parse enclosure_details attributes? Here is my XML output.
<enclosure>
<enclosure_details url="http://cdn..com/media/gallery/p18gmcacuj1o4n1572b1m1qnel1c6.jpg" length="12345" type="image/jpeg" title=<![CDATA[]]> description=<![CDATA[<p>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.</P><P align="right"><em>Image: Thinkstock</em></p>]]> />
<enclosure_details url="http://cdn..com/media/gallery/p18gmcacuj1527me8acrk2r7td7.jpg" length="12345" type="image/jpeg" title=<![CDATA[Carolina Domino Effect?]]> description=<![CDATA[<p>VantageSouth in Raleigh, N.C., and Yadkin Financial in Elkin, N.C., announced plans in late January for <a href="http://www..com/issues/179_18/vantagesouth-yadkin-deal-could-spur-meaningful-ma-in-north-carolina-1065227-1.html">a 300ドル million merger</a>. 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.</P><P align="right"><em>Bloomberg News</em></p>]]> />
<enclosure_details url="http://cdn..com/media/gallery/p18gmcacuj332qvhj7c1qbucn98.jpg" length="12345" type="image/jpeg" title=<![CDATA[Cost-Cutting Focus]]> description=<![CDATA[<p>ConnectOne in Englewood, N.J., is merging with Center Bancorp in Union, N.J., in <a href="http://www..com/video/connectone-ceo-explains-banks-merger-with-center-of-nj1065072-1.html">another MOE-like deal</a> 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.</p>]]> />
Mick MacCallum
130k40 gold badges283 silver badges284 bronze badges
asked Feb 20, 2014 at 12:41
Piyush
5901 gold badge8 silver badges23 bronze badges
1 Answer 1
Try NSXMLParser for iOS: https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSXMLParser_Class/Reference/Reference.html
And you have a tutorial here: http://iphonebyradix.blogspot.com/2011/08/parsing-xml-using-nsxmlparser.html
This delegate method get you the string inside the tag
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
}
This method gets you the attribute in your case the url inside enclosure_details
- (void)parser:(NSXMLParser *)parser foundAttributeDeclarationWithName:(NSString *)attributeName forElement:(NSString *)elementName type:(NSString *)type defaultValue:(NSString *)defaultValue;
answered Feb 20, 2014 at 12:44
Basheer_CAD
4,91927 silver badges36 bronze badges
Sign up to request clarification or add additional context in comments.
6 Comments
Piyush
i have implement same Parser, but when i get this data, i dont know how to access.. <enclosure> <enclosure_details url="cdn..com/media/gallery/p18gmcacuj1o4n1572b1m1qnel1c6.jpg" length="12345" type="image/jpeg" title=<![CDATA[]]> description=<![CDATA[<p>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.</P><P align="right"><em>Image: Thinkstock</em></p>]]> />
Basheer_CAD
NSXMLParser has a delegate methods, and it will return you the value of this tag. please follow the link
Piyush
yes sir, same i use both links for parsing, but i cant have this idea, how to implement ? I want to access all content of <enclosure_details> but i have no idea, how to do? Here is my code, if ([elementName isEqualToString:@"enclosure"]) { NSString * name = [attributeDict valueForKey:@"enclosure_details"]; [item setObject:name forKey:@"articleEnclosure"]; }
Piyush
i never use XML parser, so i have no idea. can you give me some demo code ?
Piyush
mostly i am using JSON parsing, and XML parsing too.. but in XML parsing i never do like that issue.. anyone suggest me ?
|
lang-objectivec