开发者

XML parsers used in iphone sdk

I am quite new to iphone development. I was going through tutorials on XML parsing for which NSXMLParser is used. Are there other parsers we can use for parsing XML. How d开发者_如何学Co we decide which parser to use?

Regards,

Stone


Standard parsers are NSXMLParser or c-based libxml. But there is plenty of 3rd party parsers available. Check this blog post where some of the most popular parsers reviewed and compared.


- (void)connectionDidFinishLoading:(NSURLConnection *)theConnection
{
    [self parseXMLFile:xmlFile];
    unsigned char byteBuffer[[xmlFile length]];
    [xmlFile getBytes:byteBuffer];
    NSLog(@"Output: %s", (char *)byteBuffer);
    NSLog(@"Succeeded! Received %d bytes of data",[xmlFile length]);    
    [xmlFile release];
    xmlFile = [[NSMutableData data] retain];

}


- (void)parseXMLFile:(NSData *)adatok {
    if (adatok != nil) {
        BOOL success;
        if (addressParser) 
            [addressParser release];
        addressParser = [[NSXMLParser alloc] initWithData:adatok];
        [addressParser setDelegate:self];
        [addressParser setShouldResolveExternalEntities:YES];
        success = [addressParser parse]; 

    }
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {  here You enter the node }

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { here you get the content CDDATA}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { here you end node }

hope it helps


This is a sample code from Apple.. It shows the difference between All XML parsers available..

http://developer.apple.com/library/ios/#samplecode/XMLPerformance/Introduction/Intro.html

For a newbie it will be real helpfull..Feel free to use it..


I find many tutorial and many post on this problem. There are many tutorial that don't works!!!!! I found this http://gigaom.com/apple/tutorial-build-a-simple-rss-reader-for-iphone/

and i undstend how NSXMLparser work


Personally if you're using XML and have access to the feed I would always convert the feed into plist format. This is a much better format to use with the iPhone and will save you huge amounts of time and effort.

There is also https://github.com/robbiehanson/KissXML which gives you a similar makeup to the missing NSXML classes. Its done in a way that means that if apple ever do put those classes into the iOS sdk it won't conflict at all.


If you're going to use HTML, hpple is worth trying. It's very easy to use and is going to support full XML soon.


Check this link for parse xml parse

NSString *url=@"http://www.lancers.jp/work/search/.rss";

NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
NSDictionary *dict=[XMLReader dictionaryForXMLData:data error:nil];

Click on this link

Demo code of XML

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜