iphone - XML 阅读器 : get attributes value from NSDictionary

标签 iphone ios ipad ios4 xmlreader

我正在使用 http://troybrant.net/blog/ 中的 XMLReader 类,
它将一个xml解析为一个NSDictionary,例如:

NSString *myxml=@"< students od=\"ii\">< student>< name>Raju< /name>< age>25< /age>< address>abcd< /address>< /student>< /students>";
NSDictionary *dict = [XMLReader dictionaryForXMLString:myxml error:nil];

给我一​​个像这样的 NSDictionary:

students = 
{
    "@od" = ii;
    student = 
    {
        address = abcd;
        age = 25;
        name = Raju;
    };
};

除了属性之外,我可以完美地提取这些参数中的任何一个。谁能告诉我如何获取“od”的值?
谢谢。

编辑: 我解决了这个问题,实际上我必须创建一个新的 NSDictionary :
NSDictionary *str = [students valueForKey:@"@od"];

最佳答案

为什么不使用 NSXMLParser?委托(delegate)方法返回一个 NSDictionary,其中包含 - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 属性:(NSDictionary *)attributeDict

关于iphone - XML 阅读器 : get attributes value from NSDictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7245189/

相关文章:

iphone - 在应用程序加载时从 NSUserDefaults 获取值并将其存储在全局变量中的最佳方法是什么?

ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"

iphone - 在Interface Builder中访问animationDuration和animationRepeatCount

ios - 如何将 Ubuntu 上的 Ionic 项目导出到 iOS?

objective-c - 正确使用 CIDetectorTracking

ios - 控件在初始加载时不响应 UIPopoverController 但在后续加载时响应?

iphone - 围绕 MKMapView 上的一个点

iphone - MPMoviePlayerController 上的专辑封面

ios - UIScrollView内存分配上的动画内容

objective-c - 如何设置成长效果以在该 View 内播放视频?