Re: XMLParser
Re: XMLParser
- Subject: Re: XMLParser
- From: Marcel Weiher <email@hidden>
- Date: Wed, 1 Apr 2009 14:05:08 -0700
If you like that type of higher-level, more Objective-C-like approach,
you might want to have a look at Objective-XML, and more specifically
the MAX parser ( MAX = Message oriented API for XML):
http://www.metaobject.com/blog/2009/01/iphone-xml-performance.html
http://www.metaobject.com/blog/2009/01/objective-xml-50.html
Parser callbacks in MAX are of the form:
-itemElement:(MPWXMLAttributes*)children attributes:
(MPWXMLAttributes*)attributes parser:(MPWMAXParser*)p
where <item> is a tag name. MAX handles both children and
attributes. MPWXmlAttributes handle the required XML semantics, such
as preserving order, dealing with duplicates (in the case of
children), preserving namespaces and even supporting case-insensitive
lookups for HTML. Where possible, they preserve compatibility with
NSDictionary and NSArray.
The callback can return an object, and if it does, MAX will build a
tree for you similar to a DOM, except with your objects. If you don't
return objects in your callbacks, no tree will be built.
Finally, MAX can load and parse data incrementally when given a URL
data source, is around 10x faster than NSXMLParser and can be
configured to parse HTML in addition to XML.
Cheers,
Marcel
On Mar 29, 2009, at 12:20 , David Blanton wrote:
acolol way to parse is make you element names method names
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString
*)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:
(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
elementName = [elementName stringByAppendingString:@":"];
SEL selector = NSSelectorFromString(elementName);
if([self respondsToSelector:selector])
[self performSelector:selector withObject:attributeDict];
}
Then an element parser looks like where 'properties'was an XML:
element name
- (void)properties:(NSDictionary *)attributeDict {
id obj = [attributeDict objectForKey:@"count"];
// do more
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden