如何在Objective-C中解析包含XML的NSString? [英] How do I parse an NSString containing XML in Objective-C?

查看:116
本文介绍了如何在Objective-C中解析包含XML的NSString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的iPhone应用程序中,我有以下NSString:

In my iPhone application, I have the following NSString:

NSString *myxml=@"<students>
    <student><name>Raju</name><age>25</age><address>abcd</address> 
    </student></students>";

我如何解析此字符串的XML内容?

How would I parse the XML content of this string?

推荐答案

下载:
https ://github.com/bcaccinolo/XML-to-NSDictionary

然后你只需:

NSDictionary *dic = [XMLReader dictionaryForXMLString:myxml error:nil];

结果是一个NSDictionary * dic里面有字典,数组和字符串,取决于XML:

Result is a NSDictionary *dic with dictionaries, arrays and strings inside, depending of the XML:

{
    students =     {
        student =         {
            address = abcd;
            age = 25;
            name = Raju;
        };
    };
}

这篇关于如何在Objective-C中解析包含XML的NSString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆