├── .gitignore
├── BRYHTMLParser.podspec
├── BRYHTMLParser.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ ├── xcshareddata
│ │ └── BRYHTMLParser.xccheckout
│ └── xcuserdata
│ │ └── bryan.xcuserdatad
│ │ ├── UserInterfaceState.xcuserstate
│ │ └── WorkspaceSettings.xcsettings
└── xcuserdata
│ └── bryan.xcuserdatad
│ └── xcschemes
│ ├── BRYHTMLParser.xcscheme
│ └── xcschememanagement.plist
├── BRYHTMLParser
├── BRYHTMLParser.h
├── HTMLNode.h
├── HTMLParser.h
├── HTMLParser.m
├── Info.plist
├── LibXMLHTMLNode.h
└── LibXMLHTMLNode.m
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4 |
5 | ## Build generated
6 | build/
7 | DerivedData
8 |
9 | ## Various settings
10 | *.pbxuser
11 | !default.pbxuser
12 | *.mode1v3
13 | !default.mode1v3
14 | *.mode2v3
15 | !default.mode2v3
16 | *.perspectivev3
17 | !default.perspectivev3
18 | xcuserdata
19 |
20 | ## Other
21 | *.xccheckout
22 | *.moved-aside
23 | *.xcuserstate
24 | *.xcscmblueprint
25 |
26 | ## Obj-C/Swift specific
27 | *.hmap
28 | *.ipa
29 |
30 | # CocoaPods
31 | #
32 | # We recommend against adding the Pods directory to your .gitignore. However
33 | # you should judge for yourself, the pros and cons are mentioned at:
34 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
35 | #
36 | #Pods/
37 |
38 | # Carthage
39 | #
40 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
41 | # Carthage/Checkouts
42 |
43 | Carthage/Build
44 |
--------------------------------------------------------------------------------
/BRYHTMLParser.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = 'BRYHTMLParser'
3 | s.authors = 'Bryan Irace'
4 | s.license = 'MIT'
5 | s.platform = :ios
6 | s.homepage = 'https://github.com/irace/BRYHTMLParser'
7 | s.version = '2.1.3'
8 | s.summary = 'An Objective-C wrapper around libxml for parsing HTML.'
9 | s.source = { :git => 'https://github.com/irace/BRYHTMLParser.git', :tag => "#{s.version}" }
10 | s.source_files = 'BRYHTMLParser/*.{h,m}'
11 | s.libraries = 'xml2'
12 | s.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(SDKROOT)/usr/include/libxml2' }
13 | s.frameworks = 'Foundation'
14 | s.requires_arc = true
15 | end
16 |
--------------------------------------------------------------------------------
/BRYHTMLParser.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 9356891F1B56E36E00DEAEF3 /* HTMLNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 9356891E1B56E36E00DEAEF3 /* HTMLNode.h */; };
11 | 939D8AA21B56D69100504F60 /* LibXMLHTMLNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 939D8A9E1B56D69100504F60 /* LibXMLHTMLNode.h */; };
12 | 939D8AA31B56D69100504F60 /* LibXMLHTMLNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 939D8A9F1B56D69100504F60 /* LibXMLHTMLNode.m */; };
13 | 939D8AA41B56D69100504F60 /* HTMLParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 939D8AA01B56D69100504F60 /* HTMLParser.h */; };
14 | 939D8AA51B56D69100504F60 /* HTMLParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 939D8AA11B56D69100504F60 /* HTMLParser.m */; };
15 | 939D8AA91B56D71500504F60 /* BRYHTMLParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 939D8AA81B56D6FB00504F60 /* BRYHTMLParser.h */; };
16 | 939D8AAB1B56D76100504F60 /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 939D8AAA1B56D76100504F60 /* libxml2.dylib */; };
17 | /* End PBXBuildFile section */
18 |
19 | /* Begin PBXFileReference section */
20 | 9356891E1B56E36E00DEAEF3 /* HTMLNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLNode.h; sourceTree = ""; };
21 | 939D8A821B56D5D500504F60 /* BRYHTMLParser.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = BRYHTMLParser.framework; sourceTree = BUILT_PRODUCTS_DIR; };
22 | 939D8A861B56D5D500504F60 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
23 | 939D8A9E1B56D69100504F60 /* LibXMLHTMLNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LibXMLHTMLNode.h; sourceTree = ""; };
24 | 939D8A9F1B56D69100504F60 /* LibXMLHTMLNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LibXMLHTMLNode.m; sourceTree = ""; };
25 | 939D8AA01B56D69100504F60 /* HTMLParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLParser.h; sourceTree = ""; };
26 | 939D8AA11B56D69100504F60 /* HTMLParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTMLParser.m; sourceTree = ""; };
27 | 939D8AA81B56D6FB00504F60 /* BRYHTMLParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BRYHTMLParser.h; sourceTree = ""; };
28 | 939D8AAA1B56D76100504F60 /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = usr/lib/libxml2.dylib; sourceTree = SDKROOT; };
29 | /* End PBXFileReference section */
30 |
31 | /* Begin PBXFrameworksBuildPhase section */
32 | 939D8A7E1B56D5D500504F60 /* Frameworks */ = {
33 | isa = PBXFrameworksBuildPhase;
34 | buildActionMask = 2147483647;
35 | files = (
36 | 939D8AAB1B56D76100504F60 /* libxml2.dylib in Frameworks */,
37 | );
38 | runOnlyForDeploymentPostprocessing = 0;
39 | };
40 | /* End PBXFrameworksBuildPhase section */
41 |
42 | /* Begin PBXGroup section */
43 | 939D8A781B56D5D400504F60 = {
44 | isa = PBXGroup;
45 | children = (
46 | 939D8A841B56D5D500504F60 /* BRYHTMLParser */,
47 | 939D8A831B56D5D500504F60 /* Products */,
48 | );
49 | sourceTree = "";
50 | };
51 | 939D8A831B56D5D500504F60 /* Products */ = {
52 | isa = PBXGroup;
53 | children = (
54 | 939D8A821B56D5D500504F60 /* BRYHTMLParser.framework */,
55 | );
56 | name = Products;
57 | sourceTree = "";
58 | };
59 | 939D8A841B56D5D500504F60 /* BRYHTMLParser */ = {
60 | isa = PBXGroup;
61 | children = (
62 | 939D8AA81B56D6FB00504F60 /* BRYHTMLParser.h */,
63 | 9356891E1B56E36E00DEAEF3 /* HTMLNode.h */,
64 | 939D8AA01B56D69100504F60 /* HTMLParser.h */,
65 | 939D8AA11B56D69100504F60 /* HTMLParser.m */,
66 | 939D8A9E1B56D69100504F60 /* LibXMLHTMLNode.h */,
67 | 939D8A9F1B56D69100504F60 /* LibXMLHTMLNode.m */,
68 | 939D8A851B56D5D500504F60 /* Supporting Files */,
69 | );
70 | path = BRYHTMLParser;
71 | sourceTree = "";
72 | };
73 | 939D8A851B56D5D500504F60 /* Supporting Files */ = {
74 | isa = PBXGroup;
75 | children = (
76 | 939D8AAA1B56D76100504F60 /* libxml2.dylib */,
77 | 939D8A861B56D5D500504F60 /* Info.plist */,
78 | );
79 | name = "Supporting Files";
80 | sourceTree = "";
81 | };
82 | /* End PBXGroup section */
83 |
84 | /* Begin PBXHeadersBuildPhase section */
85 | 939D8A7F1B56D5D500504F60 /* Headers */ = {
86 | isa = PBXHeadersBuildPhase;
87 | buildActionMask = 2147483647;
88 | files = (
89 | 939D8AA41B56D69100504F60 /* HTMLParser.h in Headers */,
90 | 939D8AA21B56D69100504F60 /* LibXMLHTMLNode.h in Headers */,
91 | 939D8AA91B56D71500504F60 /* BRYHTMLParser.h in Headers */,
92 | 9356891F1B56E36E00DEAEF3 /* HTMLNode.h in Headers */,
93 | );
94 | runOnlyForDeploymentPostprocessing = 0;
95 | };
96 | /* End PBXHeadersBuildPhase section */
97 |
98 | /* Begin PBXNativeTarget section */
99 | 939D8A811B56D5D500504F60 /* BRYHTMLParser */ = {
100 | isa = PBXNativeTarget;
101 | buildConfigurationList = 939D8A981B56D5D500504F60 /* Build configuration list for PBXNativeTarget "BRYHTMLParser" */;
102 | buildPhases = (
103 | 939D8A7D1B56D5D500504F60 /* Sources */,
104 | 939D8A7E1B56D5D500504F60 /* Frameworks */,
105 | 939D8A7F1B56D5D500504F60 /* Headers */,
106 | 939D8A801B56D5D500504F60 /* Resources */,
107 | );
108 | buildRules = (
109 | );
110 | dependencies = (
111 | );
112 | name = BRYHTMLParser;
113 | productName = BRYHTMLParser;
114 | productReference = 939D8A821B56D5D500504F60 /* BRYHTMLParser.framework */;
115 | productType = "com.apple.product-type.framework";
116 | };
117 | /* End PBXNativeTarget section */
118 |
119 | /* Begin PBXProject section */
120 | 939D8A791B56D5D400504F60 /* Project object */ = {
121 | isa = PBXProject;
122 | attributes = {
123 | LastUpgradeCheck = 0730;
124 | ORGANIZATIONNAME = "Bryan Irace";
125 | TargetAttributes = {
126 | 939D8A811B56D5D500504F60 = {
127 | CreatedOnToolsVersion = 6.4;
128 | };
129 | };
130 | };
131 | buildConfigurationList = 939D8A7C1B56D5D400504F60 /* Build configuration list for PBXProject "BRYHTMLParser" */;
132 | compatibilityVersion = "Xcode 3.2";
133 | developmentRegion = English;
134 | hasScannedForEncodings = 0;
135 | knownRegions = (
136 | en,
137 | );
138 | mainGroup = 939D8A781B56D5D400504F60;
139 | productRefGroup = 939D8A831B56D5D500504F60 /* Products */;
140 | projectDirPath = "";
141 | projectRoot = "";
142 | targets = (
143 | 939D8A811B56D5D500504F60 /* BRYHTMLParser */,
144 | );
145 | };
146 | /* End PBXProject section */
147 |
148 | /* Begin PBXResourcesBuildPhase section */
149 | 939D8A801B56D5D500504F60 /* Resources */ = {
150 | isa = PBXResourcesBuildPhase;
151 | buildActionMask = 2147483647;
152 | files = (
153 | );
154 | runOnlyForDeploymentPostprocessing = 0;
155 | };
156 | /* End PBXResourcesBuildPhase section */
157 |
158 | /* Begin PBXSourcesBuildPhase section */
159 | 939D8A7D1B56D5D500504F60 /* Sources */ = {
160 | isa = PBXSourcesBuildPhase;
161 | buildActionMask = 2147483647;
162 | files = (
163 | 939D8AA31B56D69100504F60 /* LibXMLHTMLNode.m in Sources */,
164 | 939D8AA51B56D69100504F60 /* HTMLParser.m in Sources */,
165 | );
166 | runOnlyForDeploymentPostprocessing = 0;
167 | };
168 | /* End PBXSourcesBuildPhase section */
169 |
170 | /* Begin XCBuildConfiguration section */
171 | 939D8A961B56D5D500504F60 /* Debug */ = {
172 | isa = XCBuildConfiguration;
173 | buildSettings = {
174 | ALWAYS_SEARCH_USER_PATHS = NO;
175 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
176 | CLANG_CXX_LIBRARY = "libc++";
177 | CLANG_ENABLE_MODULES = YES;
178 | CLANG_ENABLE_OBJC_ARC = YES;
179 | CLANG_WARN_BOOL_CONVERSION = YES;
180 | CLANG_WARN_CONSTANT_CONVERSION = YES;
181 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
182 | CLANG_WARN_EMPTY_BODY = YES;
183 | CLANG_WARN_ENUM_CONVERSION = YES;
184 | CLANG_WARN_INT_CONVERSION = YES;
185 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
186 | CLANG_WARN_UNREACHABLE_CODE = YES;
187 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
188 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
189 | COPY_PHASE_STRIP = NO;
190 | CURRENT_PROJECT_VERSION = 1;
191 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
192 | ENABLE_STRICT_OBJC_MSGSEND = YES;
193 | ENABLE_TESTABILITY = YES;
194 | GCC_C_LANGUAGE_STANDARD = gnu99;
195 | GCC_DYNAMIC_NO_PIC = NO;
196 | GCC_NO_COMMON_BLOCKS = YES;
197 | GCC_OPTIMIZATION_LEVEL = 0;
198 | GCC_PREPROCESSOR_DEFINITIONS = (
199 | "DEBUG=1",
200 | "$(inherited)",
201 | );
202 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
203 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
204 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
205 | GCC_WARN_UNDECLARED_SELECTOR = YES;
206 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
207 | GCC_WARN_UNUSED_FUNCTION = YES;
208 | GCC_WARN_UNUSED_VARIABLE = YES;
209 | IPHONEOS_DEPLOYMENT_TARGET = 8.4;
210 | MTL_ENABLE_DEBUG_INFO = YES;
211 | ONLY_ACTIVE_ARCH = YES;
212 | SDKROOT = iphoneos;
213 | TARGETED_DEVICE_FAMILY = "1,2";
214 | VERSIONING_SYSTEM = "apple-generic";
215 | VERSION_INFO_PREFIX = "";
216 | };
217 | name = Debug;
218 | };
219 | 939D8A971B56D5D500504F60 /* Release */ = {
220 | isa = XCBuildConfiguration;
221 | buildSettings = {
222 | ALWAYS_SEARCH_USER_PATHS = NO;
223 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
224 | CLANG_CXX_LIBRARY = "libc++";
225 | CLANG_ENABLE_MODULES = YES;
226 | CLANG_ENABLE_OBJC_ARC = YES;
227 | CLANG_WARN_BOOL_CONVERSION = YES;
228 | CLANG_WARN_CONSTANT_CONVERSION = YES;
229 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
230 | CLANG_WARN_EMPTY_BODY = YES;
231 | CLANG_WARN_ENUM_CONVERSION = YES;
232 | CLANG_WARN_INT_CONVERSION = YES;
233 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
234 | CLANG_WARN_UNREACHABLE_CODE = YES;
235 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
236 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
237 | COPY_PHASE_STRIP = NO;
238 | CURRENT_PROJECT_VERSION = 1;
239 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
240 | ENABLE_NS_ASSERTIONS = NO;
241 | ENABLE_STRICT_OBJC_MSGSEND = YES;
242 | GCC_C_LANGUAGE_STANDARD = gnu99;
243 | GCC_NO_COMMON_BLOCKS = YES;
244 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
245 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
246 | GCC_WARN_UNDECLARED_SELECTOR = YES;
247 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
248 | GCC_WARN_UNUSED_FUNCTION = YES;
249 | GCC_WARN_UNUSED_VARIABLE = YES;
250 | IPHONEOS_DEPLOYMENT_TARGET = 8.4;
251 | MTL_ENABLE_DEBUG_INFO = NO;
252 | SDKROOT = iphoneos;
253 | TARGETED_DEVICE_FAMILY = "1,2";
254 | VALIDATE_PRODUCT = YES;
255 | VERSIONING_SYSTEM = "apple-generic";
256 | VERSION_INFO_PREFIX = "";
257 | };
258 | name = Release;
259 | };
260 | 939D8A991B56D5D500504F60 /* Debug */ = {
261 | isa = XCBuildConfiguration;
262 | buildSettings = {
263 | CLANG_ENABLE_OBJC_ARC = YES;
264 | DEFINES_MODULE = YES;
265 | DYLIB_COMPATIBILITY_VERSION = 1;
266 | DYLIB_CURRENT_VERSION = 1;
267 | DYLIB_INSTALL_NAME_BASE = "@rpath";
268 | HEADER_SEARCH_PATHS = (
269 | "$(inherited)",
270 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
271 | "${SDK_DIR}/usr/include/libxml2",
272 | );
273 | INFOPLIST_FILE = BRYHTMLParser/Info.plist;
274 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
275 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
276 | PRODUCT_BUNDLE_IDENTIFIER = "me.irace.$(PRODUCT_NAME:rfc1034identifier)";
277 | PRODUCT_NAME = "$(TARGET_NAME)";
278 | SKIP_INSTALL = YES;
279 | };
280 | name = Debug;
281 | };
282 | 939D8A9A1B56D5D500504F60 /* Release */ = {
283 | isa = XCBuildConfiguration;
284 | buildSettings = {
285 | CLANG_ENABLE_OBJC_ARC = YES;
286 | DEFINES_MODULE = YES;
287 | DYLIB_COMPATIBILITY_VERSION = 1;
288 | DYLIB_CURRENT_VERSION = 1;
289 | DYLIB_INSTALL_NAME_BASE = "@rpath";
290 | HEADER_SEARCH_PATHS = (
291 | "$(inherited)",
292 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
293 | "${SDK_DIR}/usr/include/libxml2",
294 | );
295 | INFOPLIST_FILE = BRYHTMLParser/Info.plist;
296 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
297 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
298 | PRODUCT_BUNDLE_IDENTIFIER = "me.irace.$(PRODUCT_NAME:rfc1034identifier)";
299 | PRODUCT_NAME = "$(TARGET_NAME)";
300 | SKIP_INSTALL = YES;
301 | };
302 | name = Release;
303 | };
304 | /* End XCBuildConfiguration section */
305 |
306 | /* Begin XCConfigurationList section */
307 | 939D8A7C1B56D5D400504F60 /* Build configuration list for PBXProject "BRYHTMLParser" */ = {
308 | isa = XCConfigurationList;
309 | buildConfigurations = (
310 | 939D8A961B56D5D500504F60 /* Debug */,
311 | 939D8A971B56D5D500504F60 /* Release */,
312 | );
313 | defaultConfigurationIsVisible = 0;
314 | defaultConfigurationName = Release;
315 | };
316 | 939D8A981B56D5D500504F60 /* Build configuration list for PBXNativeTarget "BRYHTMLParser" */ = {
317 | isa = XCConfigurationList;
318 | buildConfigurations = (
319 | 939D8A991B56D5D500504F60 /* Debug */,
320 | 939D8A9A1B56D5D500504F60 /* Release */,
321 | );
322 | defaultConfigurationIsVisible = 0;
323 | defaultConfigurationName = Release;
324 | };
325 | /* End XCConfigurationList section */
326 | };
327 | rootObject = 939D8A791B56D5D400504F60 /* Project object */;
328 | }
329 |
--------------------------------------------------------------------------------
/BRYHTMLParser.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/BRYHTMLParser.xcodeproj/project.xcworkspace/xcshareddata/BRYHTMLParser.xccheckout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDESourceControlProjectFavoriteDictionaryKey
6 |
7 | IDESourceControlProjectIdentifier
8 | F7A0CEBB-15F2-465E-97CD-B68EDA2140DE
9 | IDESourceControlProjectName
10 | BRYHTMLParser
11 | IDESourceControlProjectOriginsDictionary
12 |
13 | B471BED9AD1BCDB1D65AE8593D137A88BB290F20
14 | github.com:irace/BRYHTMLParser.git
15 |
16 | IDESourceControlProjectPath
17 | BRYHTMLParser.xcodeproj
18 | IDESourceControlProjectRelativeInstallPathDictionary
19 |
20 | B471BED9AD1BCDB1D65AE8593D137A88BB290F20
21 | ../..
22 |
23 | IDESourceControlProjectURL
24 | github.com:irace/BRYHTMLParser.git
25 | IDESourceControlProjectVersion
26 | 111
27 | IDESourceControlProjectWCCIdentifier
28 | B471BED9AD1BCDB1D65AE8593D137A88BB290F20
29 | IDESourceControlProjectWCConfigurations
30 |
31 |
32 | IDESourceControlRepositoryExtensionIdentifierKey
33 | public.vcs.git
34 | IDESourceControlWCCIdentifierKey
35 | B471BED9AD1BCDB1D65AE8593D137A88BB290F20
36 | IDESourceControlWCCName
37 | BRYHTMLParser
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/BRYHTMLParser.xcodeproj/project.xcworkspace/xcuserdata/bryan.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/irace/BRYHTMLParser/ec8711bfd24bcb7a6db31602574494db44662e9d/BRYHTMLParser.xcodeproj/project.xcworkspace/xcuserdata/bryan.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/BRYHTMLParser.xcodeproj/project.xcworkspace/xcuserdata/bryan.xcuserdatad/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges
6 |
7 | SnapshotAutomaticallyBeforeSignificantChanges
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/BRYHTMLParser.xcodeproj/xcuserdata/bryan.xcuserdatad/xcschemes/BRYHTMLParser.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
38 |
39 |
44 |
45 |
47 |
53 |
54 |
55 |
56 |
57 |
63 |
64 |
65 |
66 |
67 |
68 |
78 |
79 |
85 |
86 |
87 |
88 |
89 |
90 |
96 |
97 |
103 |
104 |
105 |
106 |
108 |
109 |
112 |
113 |
114 |
--------------------------------------------------------------------------------
/BRYHTMLParser.xcodeproj/xcuserdata/bryan.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | BRYHTMLParser.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 939D8A811B56D5D500504F60
16 |
17 | primary
18 |
19 |
20 | 939D8A8C1B56D5D500504F60
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/BRYHTMLParser/BRYHTMLParser.h:
--------------------------------------------------------------------------------
1 | //
2 | // BRYHTMLParser.h
3 | // BRYHTMLParser
4 | //
5 | // Created by Bryan Irace on 7/15/15.
6 | // Copyright (c) 2015 Bryan Irace. All rights reserved.
7 | //
8 |
9 | #import "HTMLNode.h"
10 | #import "HTMLParser.h"
11 |
--------------------------------------------------------------------------------
/BRYHTMLParser/HTMLNode.h:
--------------------------------------------------------------------------------
1 | //
2 | // HTMLNode.h
3 | // BRYHTMLParser
4 | //
5 | // Created by Bryan Irace on 7/15/15.
6 | // Copyright (c) 2015 Bryan Irace. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | typedef NS_ENUM(unsigned int, HTMLNodeType) {
12 | HTMLUnkownNode,
13 |
14 | HTMLHrefNode,
15 | HTMLTextNode,
16 | HTMLSpanNode,
17 |
18 | HTMLOlNode,
19 | HTMLUlNode,
20 | HTMLLiNode,
21 |
22 | HTMLImageNode,
23 |
24 | HTMLStrongNode,
25 | HTMLEmNode,
26 | HTMLDelNode,
27 |
28 | HTMLBoldNode,
29 | HTMLItalicNode,
30 | HTMLStrikeNode,
31 |
32 | HTMLPNode,
33 | HTMLBrNode,
34 | HTMLBlockQuoteNode,
35 |
36 | HTMLPreNode,
37 | HTMLCodeNode,
38 | };
39 |
40 | @protocol HTMLNode
41 |
42 | /// Returns the first child element
43 | @property (nonatomic, readonly) id firstChild;
44 |
45 | /// Returns the plaintext contents of node
46 | @property (nonatomic, readonly, copy) NSString *contents;
47 |
48 | /// Returns the plaintext contents of this node + all children
49 | @property (nonatomic, readonly, copy) NSString *allContents;
50 |
51 | /// Returns the html contents of the node
52 | @property (nonatomic, readonly, copy) NSString *rawContents;
53 |
54 | /// Returns next sibling in tree
55 | @property (nonatomic, readonly) id nextSibling;
56 |
57 | /// Returns previous sibling in tree
58 | @property (nonatomic, readonly) id previousSibling;
59 |
60 | /// Returns the class name
61 | @property (nonatomic, readonly, copy) NSString *className;
62 |
63 | /// Returns the tag name
64 | @property (nonatomic, readonly, copy) NSString *tagName;
65 |
66 | /// Returns the parent
67 | @property (nonatomic, readonly) id parent;
68 |
69 | /// Returns the first level of children
70 | @property (nonatomic, readonly, copy) NSArray *children;
71 |
72 | /// Returns the node type if know
73 | @property (nonatomic, readonly) HTMLNodeType nodetype;
74 |
75 | /// Gets the attribute value matching tha name
76 | - (NSString *)getAttributeNamed:(NSString *)name;
77 |
78 | /// Find children with the specified tag name
79 | - (NSArray *)findChildTags:(NSString *)tagName;
80 |
81 | /// Looks for a tag name e.g. "h3"
82 | - (id )findChildTag:(NSString *)tagName;
83 |
84 | /// Returns a single child of class
85 | - (id )findChildOfClass:(NSString *)className;
86 |
87 | /// Returns all children of class
88 | - (NSArray *)findChildrenOfClass:(NSString *)className;
89 |
90 | /// Finds a single child with a matching attribute. Set `allowPartial` to match partial matches, e.g.
[findChildWithAttribute:@"src" matchingName:"google.com" allowPartial:TRUE]
91 | - (id )findChildWithAttribute:(NSString *)attribute matchingName:(NSString *)className allowPartial:(BOOL)partial;
92 |
93 | /// Finds all children with a matching attribute
94 | - (NSArray *)findChildrenWithAttribute:(NSString *)attribute matchingName:(NSString *)className allowPartial:(BOOL)partial;
95 |
96 | @end
97 |
--------------------------------------------------------------------------------
/BRYHTMLParser/HTMLParser.h:
--------------------------------------------------------------------------------
1 | //
2 | // HTMLParser.h
3 | // StackOverflow
4 | //
5 | // Created by Ben Reeves on 09/03/2010.
6 | // Copyright 2010 Ben Reeves. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "HTMLNode.h"
11 |
12 | @interface HTMLParser : NSObject
13 |
14 | /// Returns the doc tag
15 | @property (nonatomic, readonly) id doc;
16 |
17 | /// Returns the body tag
18 | @property (nonatomic, readonly) id body;
19 |
20 | /// Returns the html tag
21 | @property (nonatomic, readonly) id html;
22 |
23 | /// Returns the head tag
24 | @property (nonatomic, readonly) id head;
25 |
26 | - (instancetype)initWithContentsOfURL:(NSURL *)url error:(NSError **)error;
27 |
28 | - (instancetype)initWithData:(NSData *)data error:(NSError **)error NS_DESIGNATED_INITIALIZER;
29 |
30 | - (instancetype)initWithString:(NSString *)string error:(NSError **)error NS_DESIGNATED_INITIALIZER;
31 |
32 | @end
33 |
--------------------------------------------------------------------------------
/BRYHTMLParser/HTMLParser.m:
--------------------------------------------------------------------------------
1 | //
2 | // HTMLParser.m
3 | // StackOverflow
4 | //
5 | // Created by Ben Reeves on 09/03/2010.
6 | // Copyright 2010 Ben Reeves. All rights reserved.
7 | //
8 |
9 | #import "LibXMLHTMLNode.h"
10 | #import "HTMLParser.h"
11 | #import
12 |
13 | @implementation HTMLParser {
14 | htmlDocPtr _doc;
15 | }
16 |
17 | -(LibXMLHTMLNode*)doc
18 | {
19 | if (_doc == NULL)
20 | return NULL;
21 |
22 | return [[LibXMLHTMLNode alloc] initWithXMLNode:(xmlNode*)_doc];
23 | }
24 |
25 | -(LibXMLHTMLNode*)html
26 | {
27 | if (_doc == NULL)
28 | return NULL;
29 |
30 | return [[self doc] findChildTag:@"html"];
31 | }
32 |
33 | -(LibXMLHTMLNode*)head
34 | {
35 | if (_doc == NULL)
36 | return NULL;
37 |
38 | return [[self doc] findChildTag:@"head"];
39 | }
40 |
41 | -(LibXMLHTMLNode*)body
42 | {
43 | if (_doc == NULL)
44 | return NULL;
45 |
46 | return [[self doc] findChildTag:@"body"];
47 | }
48 |
49 | -(instancetype)initWithString:(NSString*)string error:(NSError**)error
50 | {
51 | if (self = [super init])
52 | {
53 | _doc = NULL;
54 |
55 | if ([string length] > 0)
56 | {
57 | CFStringEncoding cfenc = CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding);
58 | CFStringRef cfencstr = CFStringConvertEncodingToIANACharSetName(cfenc);
59 | const char *enc = [(__bridge NSString *)cfencstr UTF8String];
60 | // _doc = htmlParseDoc((xmlChar*)[string UTF8String], enc);
61 | int optionsHtml = HTML_PARSE_RECOVER;
62 | optionsHtml = optionsHtml | HTML_PARSE_NOERROR; //Uncomment this to see HTML errors
63 | optionsHtml = optionsHtml | HTML_PARSE_NOWARNING;
64 | _doc = htmlReadDoc ((xmlChar*)[string UTF8String], NULL, enc, optionsHtml);
65 | }
66 | else
67 | {
68 | if (error) {
69 | *error = [NSError errorWithDomain:@"HTMLParserdomain" code:1 userInfo:nil];
70 | }
71 | }
72 | }
73 |
74 | return self;
75 | }
76 |
77 | #ifdef NS_UNAVAILABLE
78 | - (instancetype)init NS_UNAVAILABLE {
79 | return nil;
80 | }
81 | #endif
82 |
83 | -(instancetype)initWithData:(NSData*)data error:(NSError**)error
84 | {
85 | if (self = [super init])
86 | {
87 | _doc = NULL;
88 |
89 | if (data)
90 | {
91 | CFStringEncoding cfenc = CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding);
92 | CFStringRef cfencstr = CFStringConvertEncodingToIANACharSetName(cfenc);
93 | const char *enc = CFStringGetCStringPtr(cfencstr, 0);
94 | //_doc = htmlParseDoc((xmlChar*)[data bytes], enc);
95 |
96 | _doc = htmlReadDoc((xmlChar*)[data bytes],
97 | "",
98 | enc,
99 | XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
100 | }
101 | else
102 | {
103 | if (error)
104 | {
105 | *error = [NSError errorWithDomain:@"HTMLParserdomain" code:1 userInfo:nil];
106 | }
107 |
108 | }
109 | }
110 |
111 | return self;
112 | }
113 |
114 | -(instancetype)initWithContentsOfURL:(NSURL*)url error:(NSError**)error
115 | {
116 |
117 | NSData * _data = [[NSData alloc] initWithContentsOfURL:url options:0 error:error];
118 |
119 | if (_data == nil || *error)
120 | {
121 | return nil;
122 | }
123 |
124 | self = [self initWithData:_data error:error];
125 |
126 |
127 | return self;
128 | }
129 |
130 |
131 | -(void)dealloc
132 | {
133 | if (_doc)
134 | {
135 | xmlFreeDoc(_doc);
136 | }
137 |
138 | }
139 |
140 | @end
141 |
--------------------------------------------------------------------------------
/BRYHTMLParser/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | $(CURRENT_PROJECT_VERSION)
23 | NSPrincipalClass
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/BRYHTMLParser/LibXMLHTMLNode.h:
--------------------------------------------------------------------------------
1 | //
2 | // HTMLNode.h
3 | // StackOverflow
4 | //
5 | // Created by Ben Reeves on 09/03/2010.
6 | // Copyright 2010 Ben Reeves. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "HTMLNode.h"
11 |
12 | @interface LibXMLHTMLNode : NSObject
13 |
14 | struct _xmlNode;
15 |
16 | /// Init with a lib xml node (shouldn't need to be called manually). Use [parser doc] to get the root Node
17 | - (instancetype)initWithXMLNode:(struct _xmlNode *)xmlNode NS_DESIGNATED_INITIALIZER;
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/BRYHTMLParser/LibXMLHTMLNode.m:
--------------------------------------------------------------------------------
1 | //
2 | // HTMLNode.m
3 | // StackOverflow
4 | //
5 | // Created by Ben Reeves on 09/03/2010.
6 | // Copyright 2010 Ben Reeves. All rights reserved.
7 | //
8 |
9 | #import "LibXMLHTMLNode.h"
10 | #import
11 |
12 | @interface LibXMLHTMLNode ()
13 |
14 | @property (nonatomic) xmlNode * node;
15 |
16 | @end
17 |
18 | @implementation LibXMLHTMLNode
19 |
20 | -(LibXMLHTMLNode*)parent
21 | {
22 | return [[LibXMLHTMLNode alloc] initWithXMLNode:_node->parent];
23 | }
24 |
25 | -(LibXMLHTMLNode*)nextSibling {
26 | return [[LibXMLHTMLNode alloc] initWithXMLNode:_node->next];
27 | }
28 |
29 | -(LibXMLHTMLNode*)previousSibling {
30 | return [[LibXMLHTMLNode alloc] initWithXMLNode:_node->prev];
31 | }
32 |
33 | void setAttributeNamed(xmlNode * node, const char * nameStr, const char * value) {
34 |
35 | char * newVal = (char *)malloc(strlen(value)+1);
36 | memcpy (newVal, value, strlen(value)+1);
37 |
38 | bool copyUsed = false;
39 |
40 | for(xmlAttrPtr attr = node->properties; NULL != attr; attr = attr->next)
41 | {
42 | if (strcmp((char*)attr->name, nameStr) == 0)
43 | {
44 | xmlNode * child = attr->children;
45 | if (child != NULL)
46 | {
47 | free(child->content);
48 | child->content = (xmlChar*)newVal;
49 |
50 | if (!copyUsed)
51 | {
52 | copyUsed = true;
53 | }
54 | }
55 |
56 | break;
57 | }
58 | }
59 |
60 | if (!copyUsed)
61 | {
62 | free(newVal);
63 | }
64 |
65 | }
66 |
67 | NSString * getAttributeNamed(xmlNode * node, const char * nameStr)
68 | {
69 | for(xmlAttrPtr attr = node->properties; NULL != attr; attr = attr->next)
70 | {
71 | if (strcmp((char*)attr->name, nameStr) == 0)
72 | {
73 | xmlNode * child = attr->children;
74 |
75 | if (child != NULL)
76 | {
77 | return [NSString stringWithCString:(void*)child->content encoding:NSUTF8StringEncoding];
78 | }
79 |
80 | break;
81 | }
82 | }
83 |
84 | return NULL;
85 | }
86 |
87 | -(NSString*)getAttributeNamed:(NSString*)name
88 | {
89 | const char * nameStr = [name UTF8String];
90 |
91 | return getAttributeNamed(_node, nameStr);
92 | }
93 |
94 | //Returns the class name
95 | -(NSString*)className
96 | {
97 | return [self getAttributeNamed:@"class"];
98 | }
99 |
100 | //Returns the tag name
101 | -(NSString*)tagName
102 | {
103 | if (_node->name == nil)
104 | return nil;
105 |
106 | return [NSString stringWithCString:(void*)_node->name encoding:NSUTF8StringEncoding];
107 | }
108 |
109 |
110 | -(LibXMLHTMLNode*)firstChild
111 | {
112 | return [[LibXMLHTMLNode alloc] initWithXMLNode:_node->children];
113 | }
114 |
115 |
116 | -(void)findChildrenWithAttribute:(const char*)attribute matchingName:(const char*)className inXMLNode:(xmlNode *)node inArray:(NSMutableArray*)array allowPartial:(BOOL)partial
117 | {
118 | xmlNode *cur_node = NULL;
119 | const char * classNameStr = className;
120 | //BOOL found = NO;
121 |
122 | for (cur_node = node; cur_node; cur_node = cur_node->next)
123 | {
124 | for(xmlAttrPtr attr = cur_node->properties; NULL != attr; attr = attr->next)
125 | {
126 |
127 | if (strcmp((char*)attr->name, attribute) == 0)
128 | {
129 | for(xmlNode * child = attr->children; NULL != child; child = child->next)
130 | {
131 |
132 | BOOL match = NO;
133 | if (!partial && strcmp((char*)child->content, classNameStr) == 0)
134 | match = YES;
135 | else if (partial && strstr ((char*)child->content, classNameStr) != NULL)
136 | match = YES;
137 |
138 | if (match)
139 | {
140 | //Found node
141 | LibXMLHTMLNode * nNode = [[LibXMLHTMLNode alloc] initWithXMLNode:cur_node];
142 | [array addObject:nNode];
143 | break;
144 | }
145 | }
146 | break;
147 | }
148 | }
149 |
150 | [self findChildrenWithAttribute:attribute matchingName:className inXMLNode:cur_node->children inArray:array allowPartial:partial];
151 | }
152 |
153 | }
154 |
155 | -(void)findChildTags:(NSString*)tagName inXMLNode:(xmlNode *)node inArray:(NSMutableArray*)array
156 | {
157 | xmlNode *cur_node = NULL;
158 | const char * tagNameStr = [tagName UTF8String];
159 |
160 | if (tagNameStr == nil)
161 | return;
162 |
163 | for (cur_node = node; cur_node; cur_node = cur_node->next)
164 | {
165 | if (cur_node->name && strcmp((char*)cur_node->name, tagNameStr) == 0)
166 | {
167 | LibXMLHTMLNode * node = [[LibXMLHTMLNode alloc] initWithXMLNode:cur_node];
168 | [array addObject:node];
169 |
170 | }
171 |
172 | [self findChildTags:tagName inXMLNode:cur_node->children inArray:array];
173 | }
174 | }
175 |
176 |
177 | -(NSArray*)findChildTags:(NSString*)tagName
178 | {
179 | NSMutableArray * array = [NSMutableArray array];
180 |
181 | [self findChildTags:tagName inXMLNode:_node->children inArray:array];
182 |
183 | return array;
184 | }
185 |
186 | -(LibXMLHTMLNode*)findChildTag:(NSString*)tagName inXMLNode:(xmlNode *)node
187 | {
188 | xmlNode *cur_node = NULL;
189 | const char * tagNameStr = [tagName UTF8String];
190 |
191 | for (cur_node = node; cur_node; cur_node = cur_node->next)
192 | {
193 | if (cur_node && cur_node->name && strcmp((char*)cur_node->name, tagNameStr) == 0)
194 | {
195 | return [[LibXMLHTMLNode alloc] initWithXMLNode:cur_node];
196 | }
197 |
198 | LibXMLHTMLNode * cNode = [self findChildTag:tagName inXMLNode:cur_node->children];
199 | if (cNode != NULL)
200 | {
201 | return cNode;
202 | }
203 | }
204 |
205 | return NULL;
206 | }
207 |
208 | -(LibXMLHTMLNode*)findChildTag:(NSString*)tagName
209 | {
210 | return [self findChildTag:tagName inXMLNode:_node->children];
211 | }
212 |
213 |
214 | -(NSArray*)children
215 | {
216 | xmlNode *cur_node = NULL;
217 | NSMutableArray * array = [NSMutableArray array];
218 |
219 | for (cur_node = _node->children; cur_node; cur_node = cur_node->next)
220 | {
221 | LibXMLHTMLNode * node = [[LibXMLHTMLNode alloc] initWithXMLNode:cur_node];
222 | [array addObject:node];
223 | }
224 |
225 | return array;
226 | }
227 |
228 | /*
229 | -(NSString*)description
230 | {
231 | NSString * string = [NSString stringWithFormat:@"<%s>%@\n", _node->name, [self contents]];
232 |
233 | for (HTMLNode * child in [self children])
234 | {
235 | string = [string stringByAppendingString:[child description]];
236 | }
237 |
238 | string = [string stringByAppendingString:[NSString stringWithFormat:@"<%s>\n", _node->name]];
239 |
240 | return string;
241 | }*/
242 |
243 | -(LibXMLHTMLNode*)findChildWithAttribute:(const char*)attribute matchingName:(const char*)name inXMLNode:(xmlNode *)node allowPartial:(BOOL)partial
244 | {
245 | xmlNode *cur_node = NULL;
246 | const char * classNameStr = name;
247 | //BOOL found = NO;
248 |
249 | if (node == NULL)
250 | return NULL;
251 |
252 | for (cur_node = node; cur_node; cur_node = cur_node->next)
253 | {
254 | for(xmlAttrPtr attr = cur_node->properties; NULL != attr; attr = attr->next)
255 | {
256 | if (strcmp((char*)attr->name, attribute) == 0)
257 | {
258 | for(xmlNode * child = attr->children; NULL != child; child = child->next)
259 | {
260 |
261 | BOOL match = NO;
262 | if (!partial && strcmp((char*)child->content, classNameStr) == 0)
263 | match = YES;
264 | else if (partial && strstr ((char*)child->content, classNameStr) != NULL)
265 | match = YES;
266 |
267 | if (match)
268 | {
269 | return [[LibXMLHTMLNode alloc] initWithXMLNode:cur_node];
270 | }
271 | }
272 | break;
273 | }
274 | }
275 |
276 | LibXMLHTMLNode * cNode = [self findChildWithAttribute:attribute matchingName:name inXMLNode:cur_node->children allowPartial:partial];
277 | if (cNode != NULL)
278 | {
279 | return cNode;
280 | }
281 | }
282 |
283 | return NULL;
284 | }
285 |
286 | -(LibXMLHTMLNode*)findChildWithAttribute:(NSString*)attribute matchingName:(NSString*)className allowPartial:(BOOL)partial
287 | {
288 | return [self findChildWithAttribute:[attribute UTF8String] matchingName:[className UTF8String] inXMLNode:_node->children allowPartial:partial];
289 | }
290 |
291 | -(LibXMLHTMLNode*)findChildOfClass:(NSString*)className
292 | {
293 | LibXMLHTMLNode * node = [self findChildWithAttribute:"class" matchingName:[className UTF8String] inXMLNode:_node->children allowPartial:NO];
294 | return node;
295 | }
296 |
297 | -(NSArray*)findChildrenWithAttribute:(NSString*)attribute matchingName:(NSString*)className allowPartial:(BOOL)partial
298 | {
299 | NSMutableArray * array = [NSMutableArray array];
300 |
301 | [self findChildrenWithAttribute:[attribute UTF8String] matchingName:[className UTF8String] inXMLNode:_node->children inArray:array allowPartial:partial];
302 |
303 | return array;
304 | }
305 |
306 |
307 | -(NSArray*)findChildrenOfClass:(NSString*)className
308 | {
309 | return [self findChildrenWithAttribute:@"class" matchingName:className allowPartial:NO];
310 | }
311 |
312 | -(instancetype)initWithXMLNode:(xmlNode*)xmlNode
313 | {
314 | if (self = [super init])
315 | {
316 | _node = xmlNode;
317 | }
318 | return self;
319 | }
320 |
321 | #ifdef NS_UNAVAILABLE
322 | - (instancetype)init NS_UNAVAILABLE {
323 | return nil;
324 | }
325 | #endif
326 |
327 | -(void)appendChildContentsToString:(NSMutableString*)string inNode:(xmlNode*)node
328 | {
329 | if (node == NULL)
330 | return;
331 |
332 | xmlNode *cur_node = NULL;
333 | for (cur_node = node; cur_node; cur_node = cur_node->next)
334 | {
335 | if (cur_node->content)
336 | {
337 | [string appendString:[NSString stringWithCString:(void*)cur_node->content encoding:NSUTF8StringEncoding]];
338 | }
339 |
340 | [self appendChildContentsToString:string inNode:cur_node->children];
341 | }
342 | }
343 |
344 | -(NSString*)contents
345 | {
346 | if (_node->children && _node->children->content)
347 | {
348 | return [NSString stringWithCString:(void*)_node->children->content encoding:NSUTF8StringEncoding];
349 | }
350 |
351 | return nil;
352 | }
353 |
354 | HTMLNodeType nodeType(xmlNode * _node)
355 | {
356 | if (_node == NULL || _node->name == NULL)
357 | return HTMLUnkownNode;
358 |
359 | const char * tagName = (const char*)_node->name;
360 | if (strcmp(tagName, "a") == 0)
361 | return HTMLHrefNode;
362 | else if (strcmp(tagName, "text") == 0)
363 | return HTMLTextNode;
364 | else if (strcmp(tagName, "code") == 0)
365 | return HTMLCodeNode;
366 | else if (strcmp(tagName, "span") == 0)
367 | return HTMLSpanNode;
368 | else if (strcmp(tagName, "p") == 0)
369 | return HTMLPNode;
370 | else if (strcmp(tagName, "ul") == 0)
371 | return HTMLUlNode;
372 | else if (strcmp(tagName, "li") == 0)
373 | return HTMLLiNode;
374 | else if (strcmp(tagName, "img") == 0)
375 | return HTMLImageNode;
376 | else if (strcmp(tagName, "ol") == 0)
377 | return HTMLOlNode;
378 | else if (strcmp(tagName, "strong") == 0)
379 | return HTMLStrongNode;
380 | else if (strcmp(tagName, "pre") == 0)
381 | return HTMLPreNode;
382 | else if (strcmp(tagName, "blockquote") == 0)
383 | return HTMLBlockQuoteNode;
384 | else if (strcmp(tagName, "b") == 0)
385 | return HTMLBoldNode;
386 | else if (strcmp(tagName, "i") == 0)
387 | return HTMLItalicNode;
388 | else if (strcmp(tagName, "strike") == 0)
389 | return HTMLStrikeNode;
390 | else if (strcmp(tagName, "br") == 0)
391 | return HTMLBrNode;
392 | else if (strcmp(tagName, "em") == 0)
393 | return HTMLEmNode;
394 | else if (strcmp(tagName, "del") == 0)
395 | return HTMLDelNode;
396 | else
397 | return HTMLUnkownNode;
398 |
399 | }
400 |
401 | -(HTMLNodeType)nodetype
402 | {
403 | return nodeType(_node);
404 | }
405 |
406 | NSString * allNodeContents(xmlNode*node)
407 | {
408 | if (node == NULL)
409 | return nil;
410 |
411 | void * contents = xmlNodeGetContent(node);
412 | if (contents)
413 | {
414 |
415 | NSString * string = [NSString stringWithCString:contents encoding:NSUTF8StringEncoding];
416 | xmlFree(contents);
417 | return string;
418 | }
419 |
420 | return @"";
421 | }
422 |
423 | -(NSString*)allContents
424 | {
425 | return allNodeContents(_node);
426 | }
427 |
428 | NSString * rawContentsOfNode(xmlNode * node)
429 | {
430 | xmlBufferPtr buffer = xmlBufferCreateSize(1000);
431 | xmlOutputBufferPtr buf = xmlOutputBufferCreateBuffer(buffer, NULL);
432 |
433 | htmlNodeDumpOutput(buf, node->doc, node, (const char*)node->doc->encoding);
434 |
435 | xmlOutputBufferFlush(buf);
436 |
437 | NSString * string = nil;
438 |
439 | if (buffer->content) {
440 | string = [[NSString alloc] initWithBytes:(const void *)xmlBufferContent(buffer) length:xmlBufferLength(buffer) encoding:NSUTF8StringEncoding];
441 | }
442 |
443 | xmlOutputBufferClose(buf);
444 | xmlBufferFree(buffer);
445 |
446 | return string;
447 | }
448 |
449 | -(NSString*)rawContents {
450 | return rawContentsOfNode(_node);
451 | }
452 |
453 | @end
454 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 Bryan Irace
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BRYHTMLParser
2 |
3 | A fork of Ben Reeves’ [Objective-C HTML Parser](https://github.com/zootreeves/Objective-C-HMTL-Parser), containing some slight improvements and CocoaPods support.
4 |
5 | ## Installation
6 |
7 | ### CocoaPods
8 |
9 | ```bash
10 | pod install BRYHTMLParser
11 | ```
12 |
13 | ### Manual
14 |
15 | 1. Open Your project in Xcode and drag and drop all `.h`/`.m` files into an appropriate folder
16 | 2. In the project settings add `/usr/include/libxml2` to the “Header search paths” field
17 | 3. Ctrl-Click the Frameworks group choose “Add -> Existing Frameworks” and from the list choose `libxml2.dylib`
18 |
19 | ## Usage
20 |
21 | ```objc
22 | NSError *error = nil;
23 | NSString *html =
24 | @""
28 | "Hello World 1"
29 | "Hello World 2";
30 | HTMLParser *parser = [[HTMLParser alloc] initWithString:html error:&error];
31 |
32 | if (error) {
33 | NSLog(@"Error: %@", error);
34 | return;
35 | }
36 |
37 | HTMLNode *bodyNode = [parser body];
38 |
39 | NSArray *inputNodes = [bodyNode findChildTags:@"input"];
40 |
41 | for (HTMLNode *inputNode in inputNodes) {
42 | if ([[inputNode getAttributeNamed:@"name"] isEqualToString:@"input2"]) {
43 | NSLog(@"%@", [inputNode getAttributeNamed:@"value"]); //Answer to first question
44 | }
45 | }
46 |
47 | NSArray *spanNodes = [bodyNode findChildTags:@"span"];
48 |
49 | for (HTMLNode *spanNode in spanNodes) {
50 | if ([[spanNode getAttributeNamed:@"class"] isEqualToString:@"spantext"]) {
51 | NSLog(@"%@", [spanNode rawContents]); //Answer to second question
52 | }
53 | }
54 |
55 | [parser release];
56 | ```
57 |
--------------------------------------------------------------------------------