Purpose
--------------
XMLDictionary is a class designed to simplify parsing and generating of XML on iOS and Mac OS. XMLDictionary is built on top of the NSXMLParser classes, but behaves more like a DOM-style parser rather than SAX parser, in that it creates a tree of objects rather than generating events at the start and end of each node.
Unlike other DOM parsers, XMLDictionary does not attempt to replicate all of the nuances of the XML standard such as the ability to nest tags within text. If you need to represent something like an HTML document then XMLDictionary won't work for you. If you want to use XML as a data interchange format for passing nested data structures then XMLDictionary may well provide a simpler solution than other DOM-based parsers.
Supported OS & SDK Versions
-----------------------------
* Supported build target - iOS 6.1 / Mac OS 10.8 (Xcode 4.6, Apple LLVM compiler 4.2)
* Earliest supported deployment target - iOS 5.0 / Mac OS 10.7
* Earliest compatible deployment target - iOS 4.3 / Mac OS 10.6
NOTE: 'Supported' means that the library has been tested with this version. 'Compatible' means that the library should work on this OS version (i.e. it doesn't rely on any unavailable SDK features) but is no longer being tested for compatibility and may require tweaking or bug fixes to run correctly.
ARC Compatibility
------------------
As of version 1.1, XMLDictionary requires ARC. If you wish to use XMLDictionary in a non-ARC project, just add the -fobjc-arc compiler flag to the XMLDictionary.m class. To do this, go to the Build Phases tab in your target settings, open the Compile Sources group, double-click XMLDictionary.m in the list and type -fobjc-arc into the popover.
If you wish to convert your whole project to ARC, comment out the #error line in XMLDictionary.m, then run the Edit > Refactor > Convert to Objective-C ARC... tool in Xcode and make sure all files that you wish to use ARC for (including XMLDictionary.m) are checked.
Thread Safety
--------------
XMLDictionary's methods should all be thread safe. It is safe to use multiple XMLDictionaryParsers concurrently on different threads, but it is not safe to call the same parser concurrently on multiple threads.
Installation
--------------
To use the XMLDictionary in an app, just drag the class files into your project.
XMLDictionaryParser
---------------------
The XMLDictionaryParser class is responsible for parsing an XML file into a dictionary. You don't normally need to use this class explicitly as you can just use the utility methods added to NSDictionary, however it can be useful if you want to modify the default parser settings.
You can create new instances of XMLDictionaryParser if you need to use multiple different settings for different dictionaries. Once you have created an XMLDictionaryParser you can use the following methods to parse XML files using that specific parser instance:
- (NSDictionary *)dictionaryWithData:(NSData *)data;
- (NSDictionary *)dictionaryWithString:(NSString *)string;
- (NSDictionary *)dictionaryWithFile:(NSString *)path;
ALternatively, you can simply modify the settings of `[XMLDictionaryParser sharedInstance]` to affect the settings for all dictionaries parsed subsequently using the NSDictionary category extension methods.
Use the following properties to tweak the parsing behaviour:
@property (nonatomic, assign) BOOL collapseTextNodes;
If YES (the default value), tags that contain only text and have no children, attributes or comments will be collapsed into a single string object, simplifying traversal of the object tree.
@property (nonatomic, assign) BOOL stripEmptyNodes;
If YES (the default value), tags that are empty (have no children, attributes, text or comments) will be stripped.
@property (nonatomic, assign) BOOL trimWhiteSpace;
If YES (the default value), leading and trailing white space will be trimmed from text nodes, and text nodes containing only white space will be omitted from the dictionary.
@property (nonatomic, assign) BOOL alwaysUseArrays;
If `YES`, the every child node will be represented as an array, even if there is only one of them. This simplifies the logic needed to cope with properties that may be duplicated because you don't need to use `[value isKindOfClass:[NSArray class]]` to check the for the singular case. Defaults to `NO`.
@property (nonatomic, assign) BOOL preserveComments;
If `YES`, XML comments will be grouped into an array under the key `__comments` and can be accessed via the `comments` method. Defaults to `NO`.
@property (nonatomic, assign) XMLDictionaryAttributesMode attributesMode;
This property controls how XML attributes are handled. The default is `XMLDictionaryAttributesModePrefixed` meaning that attributes will be included in the dictionary, with an _ (underscore) prefix to avoid namespace collisions. Alternative values are `XMLDictionaryAttributesModeDictionary`, which will place all the attributes in a separate dictionary, `XMLDictionaryAttributesModeUnprefixed`, which includes the attributes without prefix (which may cause collisions with nodes) and `XMLDictionaryAttributesModeDiscard`, which will strip the attributes.
@property (nonatomic, assign) XMLDictionaryNodeNameMode nodeNameMode;
This property controls how the node name is handled. The default value is `XMLDictionaryNodeNameModeRootOnly`, meaning that the node name will only be included in the root dictionary (the names for the children can be inferred from the dictionary keys, but the `nodeName` method won't work for anything except the root node). Alternative values are `XMLDictionaryNodeNameModeAlways`, meaning that the node name will be included in the dictionary with the key `__name` (and can be accessed using the `nodeName`) method, or `XMLDictionaryNodeNameModeNever` which will never include the `__name' key.
Category Methods
-----------------
XMLDictionary extends NSDictionary with the following methods:
+ (NSDictionary *)dictionaryWithXMLData:(NSData *)data;
Create a new NSDictionary object from XML-encoded data.
+ (NSDictionary *)dictionaryWithXMLString:(NSString *)string;
Create a new NSDictionary object from XML-encoded string.
+ (NSDictionary *)dictionaryWithXMLFile:(NSString *)path;
Create a new NSDictionary object from and XML-encoded file.
- (NSString *)attributeForKey:(NSString *)key;
Get the XML attribute for a given key (key name should not include prefix).
- (NSDictionary *)attributes;
Get a dictionary of all XML attributes for a given node's dictionary. If the node has no attributes then this will return nil.
- (NSDictionary *)childNodes;
Get a dictionary of all child nodes for a given node's dictionary. If multiple nodes have the same name they will be grouped into an array. If the node has no children then this will return nil.
- (NSArray *)comments;
Get an array of all comments for a given node. Note that the nesting relative to other nodes is not preserved. If the node has no comments then this will return nil.
- (NSString *)nodeName;
Get the name of the node. If the name is not known this will return nil.
- (NSString *)innerText;
Get the text content of the node. If the node has no text content, this will return nil;
- (NSString *)innerXML;
Get the contents of the node as an XML-encoded string. This XML string will not include the container node itself.
- (NSString *)XMLString;
Get the node and its content as an XML-encoded string. If the node name is not known, the top level tag will be called `<root>`.
- (NSArray *)arrayValueForKeyPath:(NSString *)keyPath;
Works just like `valueForKeyPath:` except that the value returned will always be an array. So if there is only a single value, it will be returned as `@[value]`.
- (NSString *)stringValueForKeyPath:(NSString *)keyPath;
Works just like `valueForKeyPath:` exce
没有合适的资源?快使用搜索试试~ 我知道了~
XMLDictionary
共24个文件
m:4个
h:3个
md:3个
3星 · 超过75%的资源 需积分: 16 48 下载量 160 浏览量
2013-12-12
23:51:37
上传
评论
收藏 43KB ZIP 举报
温馨提示
XMLDictionary 提供一种简单的方法实现 iOS 和 Mac OS X 下解析和生成 XML 的方法。XMLDictionary 将 XML 转成 NSDictionary 。
资源推荐
资源详情
资源评论
收起资源包目录
XMLDictionary.zip (24个子文件)
XMLDictionary
XMLDictionary
XMLDictionary.m 14KB
XMLDictionary.h 3KB
LICENCE.md 900B
XMLDictionary.podspec 592B
Tests
XMLTest.xcodeproj
project.xcworkspace
contents.xcworkspacedata 152B
xcuserdata
Gary.xcuserdatad
UserInterfaceState.xcuserstate 11KB
xcuserdata
Gary.xcuserdatad
xcdebugger
Breakpoints_v2.xcbkptlist 91B
xcschemes
xcschememanagement.plist 479B
XMLTest.xcscheme 3KB
project.pbxproj 13KB
.DS_Store 6KB
XMLTest
XMLTest-Info.plist 1KB
XMLTest-Prefix.pch 316B
ViewController.m 597B
en.lproj
ViewController.xib 5KB
InfoPlist.strings 45B
main.m 347B
Default-568h@2x.png 18KB
ViewController.h 226B
AppDelegate.h 374B
AppDelegate.m 2KB
README.md 10KB
RELEASE NOTES.md 765B
.gitignore 271B
共 24 条
- 1
资源评论
- clcj32192015-04-07虽然能用,但是完全不是我想要的那种读取
Soto.Pu
- 粉丝: 4
- 资源: 74
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 2016年研究生数学建模比赛B题-具有遗传性疾病和性状的遗传位点分析
- java学生成绩管理系统项目源码
- 2019.1美国数学建模比-基于 Java 实现人工鱼群算法模拟卢浮宫紧急逃生
- windows-hardware-drivers-bringup
- tps40425芯片手册
- Pango-Compa-V1.4
- Java+Swing简易斗战三国项目源码
- PCI Storage Device Management System SDMS 4.0
- hadoop安装文件.rar,内涵hadoop安装的步骤word,hadoop、hive、hbase、sqoop、mysql等
- TRichView For Delphi XE12
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功