Sie sind auf Seite 1von 9

Make NSXMLParser your friend.. codesofa - chaotic. pragmat...

http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser...

Blog (/) Code (/code) About (/sofa) Codesofa (/) July 23, 2008

Make NSXMLParser your friend.. Update:


Since this is my most read blog article and its now 2 years old, one would think that things have changed, and they have. 2 Things: First, if you are free to choose between any API data representation, use JSON or plist, JSON is especially nice, because its very small and can be parsed with YAJL
(http://github.com/gabriel/yajl-objc) or TouchJSON (http://code.google.com/p/touchcode/wiki/TouchJSON) .

And second, and foremost, please use something less painful.. like WonderXML (http://code.google.com/p/wonderxml/) it really really helps. However, if you are still up to using NSXMLParser go on reading..

For a demo on this, you may use http://svn.liip.ch/repos/public/iphone/MyBeer (http://svn.liip.ch/repos/public/iphone/MyBeer) As promised, here is a little How-I-did-it / How-To. First off: I am not an experienced SAX-User.. So this approach might be packing the problem at its tail, but this is how DOM-Users feel comfortable with ;) Lets assume we want to parse the following XML:

tranist.xml
<root> <schedules> <schedule id="0"> <from>SourceA</from> <to>DestinationA</to> <links> <link id="0"> <departure>2008-01-01 01:01</departure> <arrival>2008-01-01 01:02</arrival> <info>With food</info> <parts> <part id="0"> <departure>2008-01-01 01:01</departure> <arrival>2008-01-01 01:02</arrival> <vehicle>Walk</vehicle> </part> <part id="1"> <departure>2008-01-01 01:01</departure> <arrival>2008-01-01 01:02</arrival> <trackfrom>1</trackfrom> <trackto>2</trackto> <vehicle>Train</vehicle> </part> </parts> </link> <link id="1"> ... </link> <link id="2"> ... </link> </links> </schedule> <schedule id="1"> ... </schedule> <schedule id="2"> ... </schedule> </schedules> </root>

In human readable format, this means: We have multiple schedules with from/to etc. These schedules consist of multiple links (different connections for the same route) with departure/arrival etc. These links consist then of multiple parts/sections with various elements which are not sure to be there.. With the lets nd the element called part approach, you wont get anywhere..

The Basics
So what do we want to achieve? We want a list/array of Schedules, which have the given members. On member is a list/array of Links, also consisting of the given members and a list/array of parts with the respective members. This is also the basic idea behind my approach: for every new node-container, use a new class/object (an array will also work, but its kinda crap..) Now we have a Schedule class, a Link class and a Part class.

1 of 9

18/04/12 10:46 AM

Make NSXMLParser your friend.. codesofa - chaotic. pragmat...

http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser...

This is an example of the Link class interface:

Link.h
#import "Part.h" @interface Link : NSObject { NSString *departure; NSString *arrival; NSString *info; NSMutableArray *parts; } @property @property @property @property (nonatomic, retain) NSString *departure; (nonatomic, retain) NSString *arrival; (nonatomic, retain) NSString *info; (readonly, retain) NSMutableArray *parts;

- (void)addPart:(Part *)part; @end

We use an accessor method for the parts, because it just feels better when dealing with arrays. (Instead of later using [foo.myArray addObject:..] we have [foo addMe:..]) Also we make it easier for us, using retain properties..

The Parser setup


A short introduction into SAX: The parsing goes node by node and is not nesting-sensitive. That means that rst we get root, then schedules, then schedule, then from, then to, then links, then link, then departure etc. As soon as the parser returns you the node for example, you dont know anymore in what schedule you were. As long as you have a clearly dened structure where always every element must be present, you could do this using a counter, but as soon as you have multiple nodes with no dened count, you have a problem. What we do is known as recursive parsing. What does this mean? We implement some kind of memory. In our parser, we have 4 members and 1 method (to make actual use of the parser..):
@property @property @property @property @property (nonatomic, (nonatomic, (nonatomic, (nonatomic, (nonatomic, retain) NSMutableString *currentProperty; retain) Schedule *currentSchedule; retain) Link *currentLink; retain) Part *currentPart; readonly) NSMutableArray *schedules;

- (void)parseScheduleData:(NSData *)data parseError:(NSError **)error;

(Yes, this needs to be a NSMutableString..) Your parseScheduleData method should look similar to the following:

parseJourneyData
- (void)parseJourneyData:(NSData *)data parseError:(NSError **)err { NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data]; self.schedules = [[NSMutableArray alloc] init]; // Create our scheduler list [parser [parser [parser [parser setDelegate:self]; // The parser calls methods in this class setShouldProcessNamespaces:NO]; // We don't care about namespaces setShouldReportNamespacePrefixes:NO]; // setShouldResolveExternalEntities:NO]; // We just want data, no other stuff

[parser parse]; // Parse that data.. if (err && [parser parserError]) { *err = [parser parserError]; } [parser release]; }

Now we need those delegate methods. - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualiedName:(NSString *)qName attributes: (NSDictionary *)attributeDict - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualiedName:(NSString *)qName - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string This function is called by the parser, when it reads something between nodes. (Text that is..) Like with blah it would read blah. It is possible, that this method is called multiple times in one node. As you will see later, we dene the property currentProperty only if we nd a node, we care about. Thats why we test it against this property to make sure, that we need this property. This will then look something like this:

2 of 9

18/04/12 10:46 AM

Make NSXMLParser your friend.. codesofa - chaotic. pragmat...

http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser...

Parser
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if (self.currentProperty) { [currentProperty appendString:string]; } }

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict This is called, when the parser nds an opening element. In this case, we have a few cases, we need to distinguish. These are: Its standard property in the schedule (like <form> etc.) or its a deeper nested node (like <links>), the same for all the other nodes. How to? We dene, that we only set a member, if we are in that node. That means, only when we have entered a <part>, then currentPart is set, otherwise its nil. The same with the others. We do then need to check them in reverse order of their nesting level.. Why? Because if we would check for currentLink before currentPart, currentLink would also evaluate to YES/True and hence we will have a problem if their are elements with the same name. If we arent in any node, then there is probably a new main node comming -> in the else.. When we hit a nested node, we need to allocate the respective member of our class, so we can use it when the parser gets deeper into it. This will look like this:

Parser
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes if (qName) { elementName = qName; }

if (self.currentPart) { // Are we in a // Check for standard nodes if ([elementName isEqualToString:@"departure"] || [elementName isEqualToString:@"arrival"] || [elementName isEqualToString:@"vehicle"] || [elementName isEqu self.currentProperty = [NSMutableString string]; } } else if (self.currentLink) { // Are we in a // Check for standard nodes if ([elementName isEqualToString:@"departure"] || [elementName isEqualToString:@"arrival"] || [elementName isEqualToString:@"info"]) { self.currentProperty = [NSMutableString string]; // Check for deeper nested node } else if ([elementName isEqualToString:@"part"]) { self.currentPart = [[Part alloc] init]; // Create the element } } else if (self.currentSchedule) { // Are we in a ? // Check for standard nodes if ([elementName isEqualToString:@"from"] || [elementName isEqualToString:@"to"]) { self.currentProperty = [NSMutableString string]; // Check for deeper nested node } else if ([elementName isEqualToString:@"link"]) { self.currentLink = [[Link alloc] init]; // Create the element } } else { // We are outside of everything, so we need a // Check for deeper nested node if ([elementName isEqualToString:@"schedule"]) { self.currentSchedule = [[Schedule alloc] init]; } } }

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualiedName:(NSString *)qName Basically, the same things apply as for didStartElement above. This time, we need to clean things up and assign them if they are set :) This is a bit a pitty, since its a lot of code.. *(for not so much) Its the same checker-structure.. If we are in a deeper nested node (like <Link>) and we hit an ending element of that nested node (like </Link>), Then we need to add this element to the parent (like <Schedule>) and set it to nil See yourself:

Parser
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if (qName) { elementName = qName; } if (self.currentPart) { // Are we in a // Check for standard nodes if ([elementName isEqualToString:@"departure"]) { self.currentPart.departure = self.currentProperty; } else if ([elementName isEqualToString:@"arrival"]) { self.currentPart.arrival = self.currentProperty;

3 of 9

18/04/12 10:46 AM

Make NSXMLParser your friend.. codesofa - chaotic. pragmat...

http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser...

} else if ([elementName isEqualToString:@"vehicle"]) { self.currentPart.vehicle = self.currentProperty; } else if ([elementName isEqualToString:@"trackfrom"]) { self.currentPart.trackfrom = self.currentProperty; } else if ([elementName isEqualToString:@"trackto"]) { self.currentPart.trackto = self.currentProperty; // Are we at the end? } else if ([elementName isEqualToString:@"part"]) { [currentLink addPart:self.currentPart]; // Add to parent self.currentPart = nil; // Set nil } } else if (self.currentLink) { // Are we in a // Check for standard nodes if ([elementName isEqualToString:@"departure"]) { self.currentLink.departure = self.currentProperty; } else if ([elementName isEqualToString:@"arrival"]) { self.currentLink.arrival = self.currentProperty; } else if ([elementName isEqualToString:@"info"]) { self.currentLink.info = self.currentProperty; // Are we at the end? } else if ([elementName isEqualToString:@"link"]) { [currentSchedule addPart:self.currentLink]; // Add to parent self.currentLink = nil; // Set nil } } else if (self.currentSchedule) { // Are we in a ? // Check for standard nodes if ([elementName isEqualToString:@"from"]) { self.currentSchedule.from = self.currentProperty; } else if ([elementName isEqualToString:@"to"]) { self.currentSchedule.to = self.currentProperty; // Are we at the end? } else if ([elementName isEqualToString:@"schedule"]) { // Corrected thanks to Muhammad Ishaq &nbsp; [schedules addObject:self.currentSchedule]; // Add to the result node self.currentSchedule = nil; // Set nil } } // We reset the currentProperty, for the next textnodes.. self.currentProperty = nil; }

Finally..
Well, thats it. You can expand / shrink this principle as you like. You can also add a maxElements counter, like in the SeismicXML example of the iPhone SDK to get only a certain number of elements. You can abort the parser with [parser abortParsing]; It is important, that you dont abort while in a deeper nested node, because this could lead to inconsistencies. You will need to skip them.. Please note, that I wrote this, while watching TV, so you may need to x some syntax errors ;) But I hope you get the idea.. Posted in How-To (http://codesofa.com/blog/archive/category/how-to) , Tech (http://codesofa.com/blog/archive/category/tech) , iPhone (http://codesofa.com/blog/archive/category
/iphone)

Tagged iPhone (http://codesofa.com/blog/archive/tag/iphone) , nsxml (http://codesofa.com/blog/archive/tag/nsxml) , objective-c (http://codesofa.com/blog/archive/tag/objective-c) , parsing (http://codesofa.com/blog/archive/tag/parsing) , recursive (http://codesofa.com/blog/archive/tag/recursive) , sdk (http://codesofa.com/blog/archive/tag/sdk)

41 Comments to Make NSXMLParser your friend..


1. August 4, 2008 at 2:56 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-8) () BW I think Im missing something, at what point is the external XML les called? 2. August 4, 2008 at 3:41 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-9) (http://www.codesofa.com) Marc (http://www.codesofa.com) Right here: - (void)parseJourneyData:(NSData *)data parseError:(NSError **)err { NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data]; You can also load it with initWithContentsOfURL or with a string with [NSData initWithByes:length:] (and provide the xml string) or with [NSData initWithContentsOfFile] 3. August 4, 2008 at 3:43 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-10)
(http://www.codesofa.com) Marc (http://www.codesofa.com)

And this le is included in your controller/wherever class, where you downloaded and need your data. You then call this parser with [myParser parseJourneyData:myData parseError:&err]; 4. August 11, 2008 at 9:35 am Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-12)
(http://sudo.ch) David (http://sudo.ch)

As far as I can see you are not releasing properly; as in e.g. self.currentPart = [[Part alloc] init]; // Create the element the Part instance should be relased just after the assignment because the currentPart property has a retain attribute.

4 of 9

18/04/12 10:46 AM

Make NSXMLParser your friend.. codesofa - chaotic. pragmat...

http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser...

5. August 11, 2008 at 4:50 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-13)


(http://codesofa.com/) marc (http://codesofa.com/)

David: You are absolutely right. I actually copied the property part from some real code and wrote the other in the blog editor. Will correct it, as soon as I nd some time. Thanks! 6. August 25, 2008 at 1:25 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-23)
() matt

Thanks for this excellent tutorial this is exactly what Ive been searching for. 7. September 29, 2008 at 9:45 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-22) (http://josephcrawford.com) Joseph Crawford (http://josephcrawford.com) Thanks for this write up. I am just starting out with Cocoa and even driven xml but will be sure to give this a second read tomorrow. Any particular reason you used the dot syntax? 8. October 2, 2008 at 2:05 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-6) () Agustin @Marc: Do you have the code please?? is giving me an error 9. October 7, 2008 at 6:50 am Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-19)
(http://www.cocoachina.com/bbs/?a=lvyile) yile lv (http://www.cocoachina.com/bbs/?a=lvyile)

Thanks so much, I got the link from a friend, I will have a try~ 10. February 25, 2009 at 7:30 am Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-817) (http://blogs.kahaf.com/ishaq) Muhammad Ishaq (http://blogs.kahaf.com/ishaq) awesome! but shouldnt the last else if check for a schedule at the end instead of a link i.e. else if (self.currentSchedule) { // Are we in a ? // Check for standard nodes if ([elementName isEqualToString:@"from"]) { self.currentSchedule.from = self.currentProperty; } else if ([elementName isEqualToString:@"to"]) { self.currentSchedule.to = self.currentProperty; // Are we at the end? } else if ([elementName isEqualToString:@"link"]) { // <<<< shouldnt this line check for a @schedule instead of a @link [schedules addObject:self.currentSchedule]; // Add to the result node self.currentSchedule = nil; // Set nil } } 11. February 27, 2009 at 2:43 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-830) (http://www.codesofa.com) marc (http://www.codesofa.com) Muhammad Ishaq: Oh, yes, silly me, that is the typical copy/paste error :) 12. April 17, 2009 at 9:57 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-1247)
() greg

Do you have this code in full? I am having trouble understanding the snippets you have been so kind to show us and how they t into the whole project. Thanks for the great tutorial! 13. April 19, 2009 at 2:02 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-1253) () marc greg: Im currently doing my annual army service, will come back to your post in 2 wks 14. April 23, 2009 at 9:27 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-1264) () Nate I would love to see the complete code too. Im getting errors when Im trying to use my object classessuch a noob. 15. April 30, 2009 at 2:38 am Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/commentpage-1#comment-1278) () Parisman

Looks like there is a new XML/HTML parser on the block. May be worth a look

5 of 9

18/04/12 10:46 AM

Make NSXMLParser your friend.. codesofa - chaotic. pragmat...

http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser...

16. May 6, 2009 at 4:49 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-1419)


() Matt

I would like to know when and how to release the objects properly. Here there are apparently some memory leaks. 17. May 8, 2009 at 9:18 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-1490) () Thierry it crashes for me when release the parser on iPhone. and if I dont release it after parse, instruments nd a leak 18. May 9, 2009 at 4:10 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/commentpage-1#comment-1517) () marc

As I mentioned in the blog post and earlier in the comments, I wrote this while sitting in front of the tv in my blog editor. So there might be a few syntax errors and of course memory leaks. I try to setup a very small example of how its supposed to be connected. 19. June 18, 2009 at 1:29 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-2552) () Daniel I think this is what I need to solve my problem but the example is too complicated to understand :-( 20. July 13, 2009 at 10:41 am Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-3293)
() Danial

This is exactly what I have been searching for! I agree it is a tad complicated to follow but I will persist. However what I do not see at present is how you would drill into the various classes? So if you decided to populate a table with schedules that you then display, click on one and drill into that etc etc. :-( 21. July 28, 2009 at 3:06 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-3580) () MK in the didEndElement method, the assignment, [schedules addObject:self.currentSchedule]; Does anybody get this while printing the contents of the schedules array? 22. July 28, 2009 at 3:10 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-3581) () MK by this i meant Schedule: 0x1164d60 , was in html tags.. :( 23. January 25, 2010 at 12:06 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-6570) () pradeep joshua Hi Marc; I saw your demo project video on transport application ans saw some data(means:Make NSXMLParser your friend) load in this application. you had parse some xml in this project. my problem is how to stored in this xml data on the xml le on a single array.. i have one xml le. format to be same use for u. how to parse in this xml then how to stored the data. nombre this tag car name mydoubt: does not set the value(car details) on aparticular car name. suppose ALFA ROMEO 159 is car name.this car models are two details blow xml. To display rst car name:ALFA ROMEO 159 details:detail-1 and second car name:ALFA ROMEO 159 details:detail-2. i am try use in your concept. but not set value. how many class create .how to stored value.how to set value from array; i am trying 2weeks marc.help me marc.to send my mail id ALFA ROMEO 147 5 Puertas Compacto 105 CV 150 CV 18.820 23.620 /pub/fotos/vehiculoNuevo/180/9/371/2009/24_5/01.jpg

6 of 9

18/04/12 10:46 AM

Make NSXMLParser your friend.. codesofa - chaotic. pragmat...

http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser...

ALFA ROMEO 159 4 Puertas Berlina 120 CV 209 CV 27.970 36.330 /pub/fotos/vehiculoNuevo/180/9/429/2009/4_4/01.jpg 5 Puertas Familiar grande 120 CV 209 CV 29.470 37.830 /pub/fotos/vehiculoNuevo/180/9/429/2009/2_5/01.jpg ALFA ROMEO BRERA 3 Puertas Coupe 185 CV 260 CV 36.200 45.510 /pub/fotos/vehiculoNuevo/180/9/448/2009/6_3/01.jpg ALFA ROMEO GT 2 Puertas Coupe 140 CV 165 CV 29.040 35.020 /pub/fotos/vehiculoNuevo/180/9/325/2009/6_2/01.jpg ALFA ROMEO MITO 3 Puertas Compacto 79 CV 170 CV 14.150 21.000 /pub/fotos/vehiculoNuevo/180/9/594/2009/24_3/01.jpg ALFA ROMEO SPIDER 2 Puertas Cabrio 185 CV 260 CV

7 of 9

18/04/12 10:46 AM

Make NSXMLParser your friend.. codesofa - chaotic. pragmat...

http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser...

38.700 48.010 /pub/fotos/vehiculoNuevo/180/9/500/2009/1_2/01.jpg 24. May 3, 2010 at 1:29 am Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-8154) () Idrissa Hello Marc, this is a useful tutorial, my concern is where do you put the Data in the case where you are programming for the iPhone? cheers 25. June 23, 2010 at 1:55 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-8257) () FLHippy This article has not made XMLParser my friend. Everything seems to compile ne without warnings but the delegate methods are never called. Sure wish I could get this worked out :) 26. June 26, 2010 at 6:25 am Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-8259) () Dilip Hello, I need simple example of xml parsing. code & xml le (with 1 tag). pls help. 27. June 29, 2010 at 10:36 am Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-8263) () Frank Nice tutorial! Thx a lot. PS: just a note.. it is nice to have a link to the source code of the project in case you get some error or something =) 28. July 17, 2010 at 6:44 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-8279) (http://www.codesofa.com) marc (http://www.codesofa.com) Hi guys. Its been a while since I checked on this. Please make sure you read the Update on top of the page for more information. NSXMLParser is kind of yeah, not the way to go Id say :) 29. July 21, 2010 at 9:46 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-8283) () Georgia Hi! Thanks for the tutorial its been super helpful. Im currently having an issue where the application crashes after the parser runs successfully. I think it must be something with memory management or pointers or maybe just how the parser is exiting? Any suggestions would be greatly appreciated! 30. November 26, 2010 at 4:25 am Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-8386) (http://www.google.com) Udhaya (http://www.google.com) @Frank. hai, u got the source code rite?! just post it.. 31. February 4, 2011 at 1:41 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-8400) (http://tobiasrosengren.se/) Tobias (http://tobiasrosengren.se/) Thanks! Will try and use this in my project, is writing my rst application for mac osx now, great tutorial! 32. March 2, 2011 at 10:56 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/commentpage-1#comment-8411) () Susan

If you would start *ONLY* doing cut/paste from actual/working code all the typos would disappear. 33. March 11, 2011 at 12:04 am Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-8412) () Limunada Nice tutorial, thank you! 34. March 11, 2011 at 11:34 am Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/commentpage-1#comment-8414) (http://m-kuttner.com) Martin K (http://m-kuttner.com)

You, Sir, have been of invaluable service to me. 35. March 13, 2011 at 12:27 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-8420)
(http://www.codesofa.com) marc (http://www.codesofa.com)

8 of 9

18/04/12 10:46 AM

Make NSXMLParser your friend.. codesofa - chaotic. pragmat...

http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser...

Susan: You can always use the provided example above if you just want to copy/paste. Im not a big fan of copy/paste coding however and sincerely hope that you got the point that this entry explains a concept and is not a ready-made library for your app. 36. March 17, 2011 at 1:21 am Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-8426) () Paul Hi Marc Im new at this. Is it worth using an alternate method as mentioned in your update. Can you recommend the best option for xml parsing? Thanks for sharing P 37. June 28, 2011 at 10:11 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-8436) () luke This is the worst xml tutorial I have came across yet, its inconsistent and generally hard to follow. 38. July 7, 2011 at 3:20 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-8437)
(http://WebsiteURL) Thromordyn (http://WebsiteURL)

I see a call to - (void)addPart:(Part *)part; but nothing about implementation. I cant imagine its supposed to be empty. The whole tutorial here (which is really just bad copy-paste) is missing quite a lot, and the link to MyBeer (top of the page) blocks direct downloads (via right-click). If I want it, I have to open each and every page and copy from there. Not cool. 39. July 7, 2011 at 3:40 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-8438) (http://WebsiteURL) Thromordyn (http://WebsiteURL) And it gets better. MyBeer is 100% worthless. You shouldnt link to that not-working garbage. 40. July 8, 2011 at 7:47 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/comment-page-1#comment-8439)
(http://www.codesofa.com) marc (http://www.codesofa.com)

Id really give SVN a shot on this one.. 41. July 8, 2011 at 7:49 pm Permalink (http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html/commentpage-1#comment-8440) (http://www.codesofa.com) marc (http://www.codesofa.com)

just link me up with a better one that serves you everything on a silver platter. (or just use the mentioned libraries at the top, SAX is not for everyone)

Dare to comment?
Name

E-Mail Address Website URL Submit Comment


And long nights follow eld-days.. (http://codesofa.com/blog/archive/2008/07/21/and-long-nights-follow-eld-days.html) A short note on CLLocation / CLLocationManager (http://codesofa.com/blog/archive/2008/07/25/a-short-note-on-cllocation-cllocationmanager.html)

http://twitter.com/marcammann (http://twitter.com/marcammann) m@codesofa.com (mailto:m@codesofa.com) http://www.last.fm/user/marcammann (http://www.last.fm/user/marcammann) http://ch.linkedin.com/in/marca (http://ch.linkedin.com/in/marca) http://codesofa.com/feed (feed:http://codesofa.com/feed)

9 of 9

18/04/12 10:46 AM

Das könnte Ihnen auch gefallen