iPhone sdk 中使用的 XML 解析器

发布于 2024-10-19 01:14:10 字数 112 浏览 6 评论 0原文

我对 iPhone 开发还很陌生。我正在阅读有关使用 NSXMLParser 的 XML 解析的教程。我们是否可以使用其他解析器来解析 XML。我们如何决定使用哪个解析器?

问候,
石头

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 do we decide which parser to use?

Regards,
Stone

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

无畏 2024-10-26 01:14:10

标准解析器是 NSXMLParser 或基于 C 的 libxml。但是有很多可用的第三方解析器。查看此博客文章< /a> 其中一些最流行的解析器进行了审查和比较。

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.

∞觅青森が 2024-10-26 01:14:10
- (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 }

希望有帮助

- (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

我最亲爱的 2024-10-26 01:14:10

这是来自 Apple 的示例代码。它显示了所有可用 XML 解析器之间的差异。

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

对于新手来说,这将是非常有帮助的..随意使用它。 。

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..

坏尐絯 2024-10-26 01:14:10

我发现很多关于这个问题的教程和帖子。
很多教程都不起作用!!!!
我找到了这个
http://gigaom.com/apple/tutorial- build-a-simple-rss-reader-for-iphone/

我不明白 NSXMLparser 是如何工作的

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

万劫不复 2024-10-26 01:14:10

就我个人而言,如果您使用 XML 并且可以访问提要,我总是会将提要转换为 plist 格式。这是一种更适合 iPhone 使用的格式,可以节省您大量的时间和精力。

还有 https://github.com/robbiehanson/KissXML 可以为您提供与缺失类似的妆容NSXML 类。它的完成方式意味着如果苹果真的将这些类放入 iOS sdk 中,它根本不会发生冲突。

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.

灵芸 2024-10-26 01:14:10

如果您打算使用 HTML,hpple 值得尝试。它非常容易使用,并且很快就会支持完整的 XML。

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.

孤独难免 2024-10-26 01:14:10

检查此链接以进行解析 xml 解析

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

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

单击此链接

XML 演示代码

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文