【问题标题】:how to read attributes of an element in xml file using objective c如何使用objective c读取xml文件中元素的属性
【发布时间】:2011-04-27 11:03:07
【问题描述】:

在我的应用程序中,我从服务器获取了一个 xml 文件,其中我有一些元素的属性。我不知道如何读取属性,任何人都可以帮助我..

【问题讨论】:

  • 向我们展示您的尝试:-)

标签: objective-c xml xcode nsxmlparser


【解决方案1】:

NSXMLParser 是一个 SAX 解析器,它是 iOS SDK 的一部分。如果你的 google-fu 很强大,有很多教程可供使用。

Event-Driven XML Programming Guide

【讨论】:

    【解决方案2】:

    NSXMLParser 类中,您在该类提供的以下事件中读取元素的属性:

    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict;
    

    如果有的话,最后一个参数attributes:(NSDictionary *)attributeDict 会给你一个属性-值对的字典。

    【讨论】:

      【解决方案3】:

      你可以从下面的教程开始

      http://theappleblog.com/2008/08/04/tutorial-build-a-simple-rss-reader-for-iphone/

      然后阅读 Apple 提供的非常好的文档以符合您的要求。

      Introduction to Event-Driven XML Programming Guide for Cocoa provided by Apple.

      【讨论】:

      • 我不理解你提供的链接,请你把它解释清楚。我的 xml 文件是 我想将 ImageId、Description 和 Date 分配到三个变量,我想将每个结果保存到一个数组中。从中读取数据
      • 如果您在理解该教程时遇到问题,请查看以下内容。 dblog.com.au/general/…
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多