XMLDictionary.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // XMLDictionary.h
  3. //
  4. // Version 1.4.1
  5. //
  6. // Created by Nick Lockwood on 15/11/2010.
  7. // Copyright 2010 Charcoal Design. All rights reserved.
  8. //
  9. // Get the latest version of XMLDictionary from here:
  10. //
  11. // https://github.com/nicklockwood/XMLDictionary
  12. //
  13. // This software is provided 'as-is', without any express or implied
  14. // warranty. In no event will the authors be held liable for any damages
  15. // arising from the use of this software.
  16. //
  17. // Permission is granted to anyone to use this software for any purpose,
  18. // including commercial applications, and to alter it and redistribute it
  19. // freely, subject to the following restrictions:
  20. //
  21. // 1. The origin of this software must not be misrepresented; you must not
  22. // claim that you wrote the original software. If you use this software
  23. // in a product, an acknowledgment in the product documentation would be
  24. // appreciated but is not required.
  25. //
  26. // 2. Altered source versions must be plainly marked as such, and must not be
  27. // misrepresented as being the original software.
  28. //
  29. // 3. This notice may not be removed or altered from any source distribution.
  30. //
  31. #import <Foundation/Foundation.h>
  32. #pragma GCC diagnostic push
  33. #pragma GCC diagnostic ignored "-Wobjc-missing-property-synthesis"
  34. NS_ASSUME_NONNULL_BEGIN
  35. typedef NS_ENUM(NSInteger, XMLDictionaryAttributesMode)
  36. {
  37. XMLDictionaryAttributesModePrefixed = 0, //default
  38. XMLDictionaryAttributesModeDictionary,
  39. XMLDictionaryAttributesModeUnprefixed,
  40. XMLDictionaryAttributesModeDiscard
  41. };
  42. typedef NS_ENUM(NSInteger, XMLDictionaryNodeNameMode)
  43. {
  44. XMLDictionaryNodeNameModeRootOnly = 0, //default
  45. XMLDictionaryNodeNameModeAlways,
  46. XMLDictionaryNodeNameModeNever
  47. };
  48. static NSString *const XMLDictionaryAttributesKey = @"__attributes";
  49. static NSString *const XMLDictionaryCommentsKey = @"__comments";
  50. static NSString *const XMLDictionaryTextKey = @"__text";
  51. static NSString *const XMLDictionaryNodeNameKey = @"__name";
  52. static NSString *const XMLDictionaryAttributePrefix = @"_";
  53. @interface XMLDictionaryParser : NSObject <NSCopying>
  54. + (XMLDictionaryParser *)sharedInstance;
  55. @property (nonatomic, assign) BOOL collapseTextNodes; // defaults to YES
  56. @property (nonatomic, assign) BOOL stripEmptyNodes; // defaults to YES
  57. @property (nonatomic, assign) BOOL trimWhiteSpace; // defaults to YES
  58. @property (nonatomic, assign) BOOL alwaysUseArrays; // defaults to NO
  59. @property (nonatomic, assign) BOOL preserveComments; // defaults to NO
  60. @property (nonatomic, assign) BOOL wrapRootNode; // defaults to NO
  61. @property (nonatomic, assign) XMLDictionaryAttributesMode attributesMode;
  62. @property (nonatomic, assign) XMLDictionaryNodeNameMode nodeNameMode;
  63. - (nullable NSDictionary<NSString *, id> *)dictionaryWithParser:(NSXMLParser *)parser;
  64. - (nullable NSDictionary<NSString *, id> *)dictionaryWithData:(NSData *)data;
  65. - (nullable NSDictionary<NSString *, id> *)dictionaryWithString:(NSString *)string;
  66. - (nullable NSDictionary<NSString *, id> *)dictionaryWithFile:(NSString *)path;
  67. @end
  68. @interface NSDictionary (XMLDictionary)
  69. + (nullable NSDictionary<NSString *, id> *)dictionaryWithXMLParser:(NSXMLParser *)parser;
  70. + (nullable NSDictionary<NSString *, id> *)dictionaryWithXMLData:(NSData *)data;
  71. + (nullable NSDictionary<NSString *, id> *)dictionaryWithXMLString:(NSString *)string;
  72. + (nullable NSDictionary<NSString *, id> *)dictionaryWithXMLFile:(NSString *)path;
  73. @property (nonatomic, readonly, copy, nullable) NSDictionary<NSString *, NSString *> *attributes;
  74. @property (nonatomic, readonly, copy, nullable) NSDictionary<NSString *, id> *childNodes;
  75. @property (nonatomic, readonly, copy, nullable) NSArray<NSString *> *comments;
  76. @property (nonatomic, readonly, copy, nullable) NSString *nodeName;
  77. @property (nonatomic, readonly, copy, nullable) NSString *innerText;
  78. @property (nonatomic, readonly, copy) NSString *innerXML;
  79. @property (nonatomic, readonly, copy) NSString *XMLString;
  80. - (nullable NSArray *)arrayValueForKeyPath:(NSString *)keyPath;
  81. - (nullable NSString *)stringValueForKeyPath:(NSString *)keyPath;
  82. - (nullable NSDictionary<NSString *, id> *)dictionaryValueForKeyPath:(NSString *)keyPath;
  83. @end
  84. @interface NSString (XMLDictionary)
  85. @property (nonatomic, readonly, copy) NSString *XMLEncodedString;
  86. @end
  87. NS_ASSUME_NONNULL_END
  88. #pragma GCC diagnostic pop