XMLDictionary 提供一种简单的方法实现 iOS 和 Mac OS X 下解析和生成 XML 的方法。XMLDictionary 将 XML 转成 NSDictionary 。
实现用于优化 Windows Communication Foundation (WCF) 的 XML 读取器/编写器实现的字典。
程序集: System.Runtime.Serialization(System.Runtime.Serialization.dll 中)
名称 | 说明 | |
---|---|---|
![]() | XmlDictionary() |
创建一个空的 XmlDictionary。 |
![]() | XmlDictionary(Int32) |
创建具有初始容量的 XmlDictionary。 |
名称 | 说明 | |
---|---|---|
![]() ![]() | Empty |
获取 static 空 IXmlDictionary。 |
名称 | 说明 | |
---|---|---|
![]() | Add(String) |
将字符串添加到 XmlDictionary。 |
![]() | Equals(Object) |
确定指定的对象是否等于当前对象。(从 Object 继承。) |
![]() | Finalize() |
在垃圾回收将某一对象回收前允许该对象尝试释放资源并执行其他清理操作。(从 Object 继承。) |
![]() | GetHashCode() |
作为默认哈希函数。(从 Object 继承。) |
![]() | GetType() | |
![]() | MemberwiseClone() | |
![]() | ToString() |
返回表示当前对象的字符串。(从 Object 继承。) |
![]() | TryLookup(Int32, XmlDictionaryString) |
尝试在字典中查找项。 |
![]() | TryLookup(String, XmlDictionaryString) |
检查字典中是否有指定的字符串值。 |
![]() | TryLookup(XmlDictionaryString, XmlDictionaryString) |
检查字典中是否有指定的 XmlDictionaryString。 |
字典在常见文本字符串和整数之间建立映射,并为压缩和解压缩 XML 提供一种有效的机制。Windows Communication Foundation (WCF) 使用静态和动态 2 种字典。
使用静态字典时,通信的两端都使用预定义的字典。
使用动态字典时,发送端可以添加其映射不在静态字典中的新字符串。动态字典与消息一起在带外发送。动态字典使用 XmlBinaryWriterSession 和 XmlBinaryReaderSession 类传输消息和映射。
4.5 后可用
.NET Framework
3.0 后可用
Portable Class Library
受以下版本支持: portable .NET platforms
Silverlight
2.0 后可用
Windows Phone Silverlight
7.0 后可用
Windows Phone
8.1 后可用
此类型的任何公共静态(Visual Basic 中为 Shared)成员都是线程安全的。但不保证所有实例成员都是线程安全的。
- (NSDictionary *)dictionaryWithData:(NSData *)data;
- (NSDictionary *)dictionaryWithString:(NSString *)string;
- (NSDictionary *)dictionaryWithFile:(NSString *)path;
- (NSDictionary *)dictionaryWithParser:(NSXMLParser *)parser;
Category Methods
XMLDictionary extends NSDictionary with the following methods:
(NSDictionary *)dictionaryWithXMLParser:(NSParser *)parser;
Create a new NSDictionary object from an existing NSXMLParser. Useful if fetching data through AFNetworking.
+ (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: except that the value returned will always be a string. So if the value is a dictionary, the text value of innerText will be returned, and if the value is an array, the first item will be returned.
- (NSDictionary *)dictionaryValueForKeyPath:(NSString *)keyPath;
Works just like valueForKeyPath: except that the value returned will always be a dictionary. So if the collapseTextNodes option is enabled and the value is a string, this will convert it back to a dictionary before returning, and if the value is an array, the first item will be returned.
项目主页:https://github.com/nicklockwood/XMLDictionary