TFHppleElement.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // TFHppleElement.h
  3. // Hpple
  4. //
  5. // Created by Geoffrey Grosenbach on 1/31/09.
  6. //
  7. // Copyright (c) 2009 Topfunky Corporation, http://topfunky.com
  8. //
  9. // MIT LICENSE
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. #import <Foundation/Foundation.h>
  30. @interface TFHppleElement : NSObject
  31. - (id) initWithNode:(NSDictionary *) theNode isXML:(BOOL)isDataXML withEncoding:(NSString *)theEncoding;
  32. + (TFHppleElement *) hppleElementWithNode:(NSDictionary *) theNode isXML:(BOOL)isDataXML withEncoding:(NSString *)theEncoding;
  33. @property (nonatomic, copy, readonly) NSString *raw;
  34. // Returns this tag's innerHTML content.
  35. @property (nonatomic, copy, readonly) NSString *content;
  36. // Returns the name of the current tag, such as "h3".
  37. @property (nonatomic, copy, readonly) NSString *tagName;
  38. // Returns tag attributes with name as key and content as value.
  39. // href = 'http://peepcode.com'
  40. // class = 'highlight'
  41. @property (nonatomic, strong, readonly) NSDictionary *attributes;
  42. // Returns the children of a given node
  43. @property (nonatomic, strong, readonly) NSArray *children;
  44. // Returns the first child of a given node
  45. @property (nonatomic, strong, readonly) TFHppleElement *firstChild;
  46. // the parent of a node
  47. @property (nonatomic, unsafe_unretained, readonly) TFHppleElement *parent;
  48. // Returns YES if the node has any child
  49. // This is more efficient than using the children property since no NSArray is constructed
  50. - (BOOL)hasChildren;
  51. // Returns YES if this is a text node
  52. - (BOOL)isTextNode;
  53. // Provides easy access to the content of a specific attribute,
  54. // such as 'href' or 'class'.
  55. - (NSString *) objectForKey:(NSString *) theKey;
  56. // Returns the children whose tag name equals the given string
  57. // (comparison is performed with NSString's isEqualToString)
  58. // Returns an empty array if no matching child is found
  59. - (NSArray *) childrenWithTagName:(NSString *)tagName;
  60. // Returns the first child node whose tag name equals the given string
  61. // (comparison is performed with NSString's isEqualToString)
  62. // Returns nil if no matching child is found
  63. - (TFHppleElement *) firstChildWithTagName:(NSString *)tagName;
  64. // Returns the children whose class equals the given string
  65. // (comparison is performed with NSString's isEqualToString)
  66. // Returns an empty array if no matching child is found
  67. - (NSArray *) childrenWithClassName:(NSString *)className;
  68. // Returns the first child whose class requals the given string
  69. // (comparison is performed with NSString's isEqualToString)
  70. // Returns nil if no matching child is found
  71. - (TFHppleElement *) firstChildWithClassName:(NSString*)className;
  72. // Returns the first text node from this element's children
  73. // Returns nil if there is no text node among the children
  74. - (TFHppleElement *) firstTextChild;
  75. // Returns the string contained by the first text node from this element's children
  76. // Convenience method which can be used instead of firstTextChild.content
  77. - (NSString *) text;
  78. // Returns elements searched with xpath
  79. - (NSArray *) searchWithXPathQuery:(NSString *)xPathOrCSS;
  80. // Custom keyed subscripting
  81. - (id)objectForKeyedSubscript:(id)key;
  82. @end