Skip to content
This repository
Browse code

Swapped in libxml support and removed the TBXML dependency.

* Added a bunch of new test cases to make sure libxml works correctly.
* Fixed issue where chinese characters weren't processed correctly.
* Fixed issue where invalid XML caused a crash.
  • Loading branch information...
commit b00d359a7a5fd660cbd45669a7fdd0bc86f06783 1 parent 2c99581
John Blanco authored
30 EncodingTests.m
... ... @@ -0,0 +1,30 @@
  1 +//
  2 +// EncodingTests.m
  3 +// RaptureXML
  4 +//
  5 +// Created by John Blanco on 3/31/12.
  6 +// Copyright (c) 2012 Rapture In Venice. All rights reserved.
  7 +//
  8 +
  9 +#import "RXMLElement.h"
  10 +
  11 +@interface EncodingTests : SenTestCase {
  12 + NSString *chineseXML_;
  13 +}
  14 +
  15 +@end
  16 +
  17 +
  18 +
  19 +@implementation EncodingTests
  20 +
  21 +- (void)setUp {
  22 + chineseXML_ = @"<condition data=\"以晴为主\"/>";
  23 +}
  24 +
  25 +- (void)testChinese {
  26 + RXMLElement *rxml = [RXMLElement elementFromXMLString:chineseXML_ withEncoding:NSUTF8StringEncoding];
  27 + STAssertEqualObjects([rxml attribute:@"data"], @"以晴为主", nil);
  28 +}
  29 +
  30 +@end
10 README
@@ -6,7 +6,7 @@ Why do we need *another* XML library?
6 6 -------------------------------------
7 7
8 8
9   -You tell me. Processing XML in Objective-C is an awful, frustrating experience and the resulting code is never readable. I'm tired of it! RaptureXML solves this by providing a *powerful* new interface on top of TBXML. Imagine for a minute the code you'd write to process the XML for a list of baseball team members, retrieving their numbers, names, and positions using your favorite XML processing library. Now, take a look at how you do it with RaptureXML:
  9 +You tell me. Processing XML in Objective-C is an awful, frustrating experience and the resulting code is never readable. I'm tired of it! RaptureXML solves this by providing a *powerful* new interface on top of the native libxml2. Imagine for a minute the code you'd write to process the XML for a list of baseball team members, retrieving their numbers, names, and positions using your favorite XML processing library. Now, take a look at how you do it with RaptureXML:
10 10
11 11 RXMLElement *rxml = [RXMLElement elementFromXMLFile:@"players.xml"];
12 12
@@ -28,7 +28,7 @@ RaptureXML processes XML in two steps: load and path. This means that you first
28 28
29 29 You can load the XML with any of the following constructors:
30 30
31   - RXMLElement *rxml = [RXMLElement elementFromXMLString:@"...my xml..."];
  31 + RXMLElement *rxml = [RXMLElement elementFromXMLString:@"...my xml..." withEncoding:NSUTF8StringEncoding];
32 32 RXMLElement *rxml = [RXMLElement elementFromXMLFile:@"myfile.xml"];
33 33 RXMLElement *rxml = [RXMLElement elementFromXMLFilename:@"myfile" elementFromXMLFilename:@"xml"];
34 34 RXMLElement *rxml = [RXMLElement elementFromURL:[NSURL URLWithString:@"...my url..."]];
@@ -120,10 +120,12 @@ Adding RaptureXML to Your Project
120 120 ---------------------------------
121 121
122 122
123   -Two steps:
  123 +Just a few easy steps:
124 124
125 125 * Copy the RaptureXML/Library folder into your own project and import "RXMLElement.h" somewheres.
126 126 * Link in libz.dylib to your target.
  127 + * Link in libxml2.dylib to your target.
  128 + * In your build settings, for the key "Header Search Paths", add "$(SDK_DIR)"/usr/include/libxml2
127 129
128 130
129 131 -----------------------
@@ -132,5 +134,3 @@ Who created RaptureXML?
132 134
133 135 RaptureXML was created by John Blanco <john.blanco@raptureinvenice.com> of Rapture In Venice because he got sick of using all of the bizarre XML solutions for iPhone development. If you like this code and/or need an iOS consultant, get in touch with me via my website, http://raptureinvenice.com. :-)
134 136
135   -TBXML, which RaptureXML currently encapsulates and has modified, was written by Tom Bradley and his original version can be found at http://www.tbxml.co.uk/TBXML/TBXML_Free.html.
136   -
62 RaptureXML.xcodeproj/project.pbxproj
@@ -7,42 +7,40 @@
7 7 objects = {
8 8
9 9 /* Begin PBXBuildFile section */
  10 + 02041DB81526A71200D1F36A /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 02041DB71526A71200D1F36A /* libxml2.dylib */; };
  11 + 02041DBA1526B0DE00D1F36A /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 02041DB71526A71200D1F36A /* libxml2.dylib */; };
  12 + 02041DBD1526BF2A00D1F36A /* SimpleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DEB8ECA1467ED9C00024989 /* SimpleTests.m */; };
  13 + 02041DBF1526CACD00D1F36A /* TextConversionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DEB8ECB1467ED9C00024989 /* TextConversionTests.m */; };
  14 + 02041DC01526CB0000D1F36A /* WildcardTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DEB8ECC1467ED9C00024989 /* WildcardTests.m */; };
10 15 0252B2DF142ADFC60018B75D /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0252B2DE142ADFC60018B75D /* SenTestingKit.framework */; };
11 16 0252B2E0142ADFC60018B75D /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0252B2C3142ADFC60018B75D /* UIKit.framework */; };
12 17 0252B2E1142ADFC60018B75D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0252B2C5142ADFC60018B75D /* Foundation.framework */; };
13 18 0252B2E2142ADFC60018B75D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0252B2C7142ADFC60018B75D /* CoreGraphics.framework */; };
14   - 027DAC3214FBF443001BA563 /* NSDataAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 027DAC2D14FBF443001BA563 /* NSDataAdditions.m */; };
15 19 027DAC3314FBF443001BA563 /* RXMLElement.m in Sources */ = {isa = PBXBuildFile; fileRef = 027DAC2F14FBF443001BA563 /* RXMLElement.m */; };
16   - 027DAC3414FBF443001BA563 /* TBXML.m in Sources */ = {isa = PBXBuildFile; fileRef = 027DAC3114FBF443001BA563 /* TBXML.m */; };
17   - 027DAC3514FBF463001BA563 /* NSDataAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 027DAC2D14FBF443001BA563 /* NSDataAdditions.m */; };
18 20 027DAC3614FBF465001BA563 /* RXMLElement.m in Sources */ = {isa = PBXBuildFile; fileRef = 027DAC2F14FBF443001BA563 /* RXMLElement.m */; };
19   - 027DAC3714FBF468001BA563 /* TBXML.m in Sources */ = {isa = PBXBuildFile; fileRef = 027DAC3114FBF443001BA563 /* TBXML.m */; };
  21 + 02F3A3FF1526D22600E8C822 /* players.xml in Resources */ = {isa = PBXBuildFile; fileRef = 0DEB8F2D14681BD800024989 /* players.xml */; };
  22 + 02F3A4001526D39000E8C822 /* DeepTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DEB8EC81467ED9C00024989 /* DeepTests.m */; };
  23 + 02F3A4011526D39800E8C822 /* DeepChildrenTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DEB8EC71467ED9C00024989 /* DeepChildrenTests.m */; };
  24 + 02F3A4021526D45B00E8C822 /* ErrorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DEB8EC91467ED9C00024989 /* ErrorTests.m */; };
  25 + 02F3A4051526D7BC00E8C822 /* EncodingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 02F3A4041526D7BC00E8C822 /* EncodingTests.m */; };
20 26 0DEB8EB51467EC9B00024989 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0252B2C5142ADFC60018B75D /* Foundation.framework */; };
21 27 0DEB8ECD1467ED9C00024989 /* BoundaryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DEB8EC61467ED9C00024989 /* BoundaryTests.m */; };
22   - 0DEB8ECE1467ED9C00024989 /* DeepChildrenTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DEB8EC71467ED9C00024989 /* DeepChildrenTests.m */; };
23   - 0DEB8ECF1467ED9C00024989 /* DeepTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DEB8EC81467ED9C00024989 /* DeepTests.m */; };
24   - 0DEB8ED01467ED9C00024989 /* ErrorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DEB8EC91467ED9C00024989 /* ErrorTests.m */; };
25   - 0DEB8ED11467ED9C00024989 /* SimpleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DEB8ECA1467ED9C00024989 /* SimpleTests.m */; };
26   - 0DEB8ED21467ED9C00024989 /* TextConversionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DEB8ECB1467ED9C00024989 /* TextConversionTests.m */; };
27   - 0DEB8ED31467ED9C00024989 /* WildcardTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DEB8ECC1467ED9C00024989 /* WildcardTests.m */; };
28 28 0DEB8F2C14681A9400024989 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 0252B305142AE3FF0018B75D /* libz.dylib */; };
29   - 0DEB8F2E14681BD800024989 /* players.xml in Resources */ = {isa = PBXBuildFile; fileRef = 0DEB8F2D14681BD800024989 /* players.xml */; };
30 29 /* End PBXBuildFile section */
31 30
32 31 /* Begin PBXFileReference section */
  32 + 02041DB71526A71200D1F36A /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = usr/lib/libxml2.dylib; sourceTree = SDKROOT; };
  33 + 02041DC21526D03A00D1F36A /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; };
33 34 0252B2C3142ADFC60018B75D /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
34 35 0252B2C5142ADFC60018B75D /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
35 36 0252B2C7142ADFC60018B75D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
36 37 0252B2DD142ADFC60018B75D /* RaptureXMLTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RaptureXMLTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
37 38 0252B2DE142ADFC60018B75D /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
38 39 0252B305142AE3FF0018B75D /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
39   - 027DAC2C14FBF443001BA563 /* NSDataAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSDataAdditions.h; sourceTree = "<group>"; };
40   - 027DAC2D14FBF443001BA563 /* NSDataAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSDataAdditions.m; sourceTree = "<group>"; };
41 40 027DAC2E14FBF443001BA563 /* RXMLElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RXMLElement.h; sourceTree = "<group>"; };
42 41 027DAC2F14FBF443001BA563 /* RXMLElement.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RXMLElement.m; sourceTree = "<group>"; };
43   - 027DAC3014FBF443001BA563 /* TBXML.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TBXML.h; sourceTree = "<group>"; };
44   - 027DAC3114FBF443001BA563 /* TBXML.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TBXML.m; sourceTree = "<group>"; };
45 42 027DAC3814FBF4B5001BA563 /* Library-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Library-Prefix.pch"; sourceTree = "<group>"; };
  43 + 02F3A4041526D7BC00E8C822 /* EncodingTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EncodingTests.m; sourceTree = SOURCE_ROOT; };
46 44 0DEB8EB41467EC9B00024989 /* libRaptureXML.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRaptureXML.a; sourceTree = BUILT_PRODUCTS_DIR; };
47 45 0DEB8EC61467ED9C00024989 /* BoundaryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BoundaryTests.m; path = Tests/BoundaryTests.m; sourceTree = SOURCE_ROOT; };
48 46 0DEB8EC71467ED9C00024989 /* DeepChildrenTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DeepChildrenTests.m; path = Tests/DeepChildrenTests.m; sourceTree = SOURCE_ROOT; };
@@ -60,6 +58,7 @@
60 58 isa = PBXFrameworksBuildPhase;
61 59 buildActionMask = 2147483647;
62 60 files = (
  61 + 02041DBA1526B0DE00D1F36A /* libxml2.dylib in Frameworks */,
63 62 0DEB8F2C14681A9400024989 /* libz.dylib in Frameworks */,
64 63 0252B2DF142ADFC60018B75D /* SenTestingKit.framework in Frameworks */,
65 64 0252B2E0142ADFC60018B75D /* UIKit.framework in Frameworks */,
@@ -72,6 +71,7 @@
72 71 isa = PBXFrameworksBuildPhase;
73 72 buildActionMask = 2147483647;
74 73 files = (
  74 + 02041DB81526A71200D1F36A /* libxml2.dylib in Frameworks */,
75 75 0DEB8EB51467EC9B00024989 /* Foundation.framework in Frameworks */,
76 76 );
77 77 runOnlyForDeploymentPostprocessing = 0;
@@ -82,6 +82,7 @@
82 82 0252B2B4142ADFC60018B75D = {
83 83 isa = PBXGroup;
84 84 children = (
  85 + 02041DC21526D03A00D1F36A /* MediaPlayer.framework */,
85 86 027DAC3814FBF4B5001BA563 /* Library-Prefix.pch */,
86 87 027DAC2B14FBF443001BA563 /* RaptureXML */,
87 88 0252B2E5142ADFC60018B75D /* Tests */,
@@ -102,6 +103,7 @@
102 103 0252B2C2142ADFC60018B75D /* Frameworks */ = {
103 104 isa = PBXGroup;
104 105 children = (
  106 + 02041DB71526A71200D1F36A /* libxml2.dylib */,
105 107 0252B305142AE3FF0018B75D /* libz.dylib */,
106 108 0252B2C3142ADFC60018B75D /* UIKit.framework */,
107 109 0252B2C5142ADFC60018B75D /* Foundation.framework */,
@@ -123,6 +125,7 @@
123 125 0DEB8ECA1467ED9C00024989 /* SimpleTests.m */,
124 126 0DEB8ECB1467ED9C00024989 /* TextConversionTests.m */,
125 127 0DEB8ECC1467ED9C00024989 /* WildcardTests.m */,
  128 + 02F3A4041526D7BC00E8C822 /* EncodingTests.m */,
126 129 );
127 130 name = Tests;
128 131 path = RaptureXMLTests;
@@ -131,12 +134,8 @@
131 134 027DAC2B14FBF443001BA563 /* RaptureXML */ = {
132 135 isa = PBXGroup;
133 136 children = (
134   - 027DAC2C14FBF443001BA563 /* NSDataAdditions.h */,
135   - 027DAC2D14FBF443001BA563 /* NSDataAdditions.m */,
136 137 027DAC2E14FBF443001BA563 /* RXMLElement.h */,
137 138 027DAC2F14FBF443001BA563 /* RXMLElement.m */,
138   - 027DAC3014FBF443001BA563 /* TBXML.h */,
139   - 027DAC3114FBF443001BA563 /* TBXML.m */,
140 139 );
141 140 path = RaptureXML;
142 141 sourceTree = "<group>";
@@ -195,7 +194,7 @@
195 194 0252B2B6142ADFC60018B75D /* Project object */ = {
196 195 isa = PBXProject;
197 196 attributes = {
198   - LastUpgradeCheck = 0420;
  197 + LastUpgradeCheck = 0430;
199 198 ORGANIZATIONNAME = "Rapture In Venice";
200 199 };
201 200 buildConfigurationList = 0252B2B9142ADFC60018B75D /* Build configuration list for PBXProject "RaptureXML" */;
@@ -221,7 +220,7 @@
221 220 isa = PBXResourcesBuildPhase;
222 221 buildActionMask = 2147483647;
223 222 files = (
224   - 0DEB8F2E14681BD800024989 /* players.xml in Resources */,
  223 + 02F3A3FF1526D22600E8C822 /* players.xml in Resources */,
225 224 );
226 225 runOnlyForDeploymentPostprocessing = 0;
227 226 };
@@ -249,15 +248,14 @@
249 248 buildActionMask = 2147483647;
250 249 files = (
251 250 0DEB8ECD1467ED9C00024989 /* BoundaryTests.m in Sources */,
252   - 0DEB8ECE1467ED9C00024989 /* DeepChildrenTests.m in Sources */,
253   - 0DEB8ECF1467ED9C00024989 /* DeepTests.m in Sources */,
254   - 0DEB8ED01467ED9C00024989 /* ErrorTests.m in Sources */,
255   - 0DEB8ED11467ED9C00024989 /* SimpleTests.m in Sources */,
256   - 0DEB8ED21467ED9C00024989 /* TextConversionTests.m in Sources */,
257   - 0DEB8ED31467ED9C00024989 /* WildcardTests.m in Sources */,
258   - 027DAC3214FBF443001BA563 /* NSDataAdditions.m in Sources */,
259 251 027DAC3314FBF443001BA563 /* RXMLElement.m in Sources */,
260   - 027DAC3414FBF443001BA563 /* TBXML.m in Sources */,
  252 + 02041DBD1526BF2A00D1F36A /* SimpleTests.m in Sources */,
  253 + 02041DBF1526CACD00D1F36A /* TextConversionTests.m in Sources */,
  254 + 02041DC01526CB0000D1F36A /* WildcardTests.m in Sources */,
  255 + 02F3A4001526D39000E8C822 /* DeepTests.m in Sources */,
  256 + 02F3A4011526D39800E8C822 /* DeepChildrenTests.m in Sources */,
  257 + 02F3A4021526D45B00E8C822 /* ErrorTests.m in Sources */,
  258 + 02F3A4051526D7BC00E8C822 /* EncodingTests.m in Sources */,
261 259 );
262 260 runOnlyForDeploymentPostprocessing = 0;
263 261 };
@@ -265,9 +263,7 @@
265 263 isa = PBXSourcesBuildPhase;
266 264 buildActionMask = 2147483647;
267 265 files = (
268   - 027DAC3514FBF463001BA563 /* NSDataAdditions.m in Sources */,
269 266 027DAC3614FBF465001BA563 /* RXMLElement.m in Sources */,
270   - 027DAC3714FBF468001BA563 /* TBXML.m in Sources */,
271 267 );
272 268 runOnlyForDeploymentPostprocessing = 0;
273 269 };
@@ -327,6 +323,7 @@
327 323 GCC_PRECOMPILE_PREFIX_HEADER = YES;
328 324 GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch";
329 325 GCC_VERSION = "";
  326 + HEADER_SEARCH_PATHS = "\"$(SDK_DIR)\"/usr/include/libxml2/**";
330 327 PRODUCT_NAME = "$(TARGET_NAME)";
331 328 TEST_AFTER_BUILD = YES;
332 329 TEST_HOST = "$(BUNDLE_LOADER)";
@@ -344,6 +341,7 @@
344 341 GCC_PRECOMPILE_PREFIX_HEADER = YES;
345 342 GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch";
346 343 GCC_VERSION = "";
  344 + HEADER_SEARCH_PATHS = "\"$(SDK_DIR)\"/usr/include/libxml2/**";
347 345 PRODUCT_NAME = "$(TARGET_NAME)";
348 346 TEST_AFTER_BUILD = YES;
349 347 TEST_HOST = "$(BUNDLE_LOADER)";
@@ -358,6 +356,7 @@
358 356 GCC_PRECOMPILE_PREFIX_HEADER = YES;
359 357 GCC_PREFIX_HEADER = "Library-Prefix.pch";
360 358 GCC_VERSION = "";
  359 + HEADER_SEARCH_PATHS = "\"$(SDK_DIR)\"/usr/include/libxml2/**";
361 360 IPHONEOS_DEPLOYMENT_TARGET = 5.0;
362 361 PRODUCT_NAME = "$(TARGET_NAME)";
363 362 SKIP_INSTALL = YES;
@@ -371,6 +370,7 @@
371 370 GCC_PRECOMPILE_PREFIX_HEADER = YES;
372 371 GCC_PREFIX_HEADER = "Library-Prefix.pch";
373 372 GCC_VERSION = "";
  373 + HEADER_SEARCH_PATHS = "\"$(SDK_DIR)\"/usr/include/libxml2/**";
374 374 IPHONEOS_DEPLOYMENT_TARGET = 5.0;
375 375 PRODUCT_NAME = "$(TARGET_NAME)";
376 376 SKIP_INSTALL = YES;
66 RaptureXML/NSDataAdditions.h
... ... @@ -1,66 +0,0 @@
1   -
2   -#import <Foundation/Foundation.h>
3   -
4   -@interface NSData (NSDataAdditions)
5   -
6   -// ================================================================================================
7   -// Created by Tom Bradley on 21/10/2009.
8   -// Version 1.4
9   -//
10   -// Copyright (c) 2009 Tom Bradley
11   -//
12   -// Permission is hereby granted, free of charge, to any person obtaining a copy
13   -// of this software and associated documentation files (the "Software"), to deal
14   -// in the Software without restriction, including without limitation the rights
15   -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16   -// copies of the Software, and to permit persons to whom the Software is
17   -// furnished to do so, subject to the following conditions:
18   -//
19   -// The above copyright notice and this permission notice shall be included in
20   -// all copies or substantial portions of the Software.
21   -//
22   -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23   -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24   -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25   -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26   -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27   -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28   -// THE SOFTWARE.
29   -// ================================================================================================
30   -
31   -+ (NSData *) dataWithUncompressedContentsOfFile:(NSString *)aFile;
32   -
33   -
34   -
35   -// ================================================================================================
36   -// base64.h
37   -// ViewTransitions
38   -//
39   -// Created by Neo on 5/11/08.
40   -// Copyright 2008 Kaliware, LLC. All rights reserved.
41   -//
42   -// FOUND HERE http://idevkit.com/forums/tutorials-code-samples-sdk/8-nsdata-base64-extension.html
43   -// ================================================================================================
44   -+ (NSData *) dataWithBase64EncodedString:(NSString *) string;
45   -- (id) initWithBase64EncodedString:(NSString *) string;
46   -
47   -- (NSString *) base64Encoding;
48   -- (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength;
49   -
50   -
51   -
52   -// ================================================================================================
53   -// NSData+gzip.h
54   -// Drip
55   -//
56   -// Created by Nur Monson on 8/21/07.
57   -// Copyright 2007 theidiotproject. All rights reserved.
58   -//
59   -// FOUND HERE http://code.google.com/p/drop-osx/source/browse/trunk/Source/NSData%2Bgzip.h
60   -// ================================================================================================
61   -- (NSData *)gzipDeflate;
62   -- (NSData *)gzipInflate;
63   -
64   -
65   -
66   -@end
310 RaptureXML/NSDataAdditions.m
... ... @@ -1,310 +0,0 @@
1   -
2   -#import "NSDataAdditions.h"
3   -
4   -#import <zlib.h>
5   -
6   -
7   -@implementation NSData (NSDataAdditions)
8   -
9   -// ================================================================================================
10   -// Created by Tom Bradley on 21/10/2009.
11   -// Version 1.4
12   -//
13   -// Copyright (c) 2009 Tom Bradley
14   -//
15   -// Permission is hereby granted, free of charge, to any person obtaining a copy
16   -// of this software and associated documentation files (the "Software"), to deal
17   -// in the Software without restriction, including without limitation the rights
18   -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19   -// copies of the Software, and to permit persons to whom the Software is
20   -// furnished to do so, subject to the following conditions:
21   -//
22   -// The above copyright notice and this permission notice shall be included in
23   -// all copies or substantial portions of the Software.
24   -//
25   -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26   -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27   -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28   -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29   -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30   -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31   -// THE SOFTWARE.
32   -// ================================================================================================
33   -
34   -+ (NSData *) dataWithUncompressedContentsOfFile:(NSString *)aFile {
35   -
36   - NSData * result;
37   -
38   - if ([[aFile pathExtension] isEqualToString:@"gz"]) {
39   - NSData * compressedData = [NSData dataWithContentsOfFile:aFile];
40   - result = [compressedData gzipInflate];
41   - }
42   - else
43   - result = [NSData dataWithContentsOfFile:aFile];
44   -
45   - return result;
46   -}
47   -
48   -
49   -
50   -
51   -
52   -// ================================================================================================
53   -// base64.m
54   -// ViewTransitions
55   -//
56   -// Created by Neo on 5/11/08.
57   -// Copyright 2008 Kaliware, LLC. All rights reserved.
58   -//
59   -// Created by khammond on Mon Oct 29 2001.
60   -// Formatted by Timothy Hatcher on Sun Jul 4 2004.
61   -// Copyright (c) 2001 Kyle Hammond. All rights reserved.
62   -// Original development by Dave Winer.
63   -//
64   -// FOUND HERE http://idevkit.com/forums/tutorials-code-samples-sdk/8-nsdata-base64-extension.html
65   -// ================================================================================================
66   -
67   -static char encodingTable[64] = {
68   - 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
69   - 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
70   - 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
71   - 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' };
72   -
73   -
74   -+ (NSData *) dataWithBase64EncodedString:(NSString *) string {
75   - NSData *result = [[NSData alloc] initWithBase64EncodedString:string];
76   - return [result autorelease];
77   -}
78   -
79   -- (id) initWithBase64EncodedString:(NSString *) string {
80   - NSMutableData *mutableData = nil;
81   -
82   - if( string ) {
83   - unsigned long ixtext = 0;
84   - unsigned long lentext = 0;
85   - unsigned char ch = 0;
86   - unsigned char inbuf[4], outbuf[3];
87   - short i = 0, ixinbuf = 0;
88   - BOOL flignore = NO;
89   - BOOL flendtext = NO;
90   - NSData *base64Data = nil;
91   - const unsigned char *base64Bytes = nil;
92   -
93   - memset(inbuf, 0, 4);
94   - // Convert the string to ASCII data.
95   - base64Data = [string dataUsingEncoding:NSASCIIStringEncoding];
96   - base64Bytes = [base64Data bytes];
97   - mutableData = [NSMutableData dataWithCapacity:[base64Data length]];
98   - lentext = [base64Data length];
99   -
100   - while( YES ) {
101   - if( ixtext >= lentext ) break;
102   - ch = base64Bytes[ixtext++];
103   - flignore = NO;
104   -
105   - if( ( ch >= 'A' ) && ( ch <= 'Z' ) ) ch = ch - 'A';
106   - else if( ( ch >= 'a' ) && ( ch <= 'z' ) ) ch = ch - 'a' + 26;
107   - else if( ( ch >= '0' ) && ( ch <= '9' ) ) ch = ch - '0' + 52;
108   - else if( ch == '+' ) ch = 62;
109   - else if( ch == '=' ) flendtext = YES;
110   - else if( ch == '/' ) ch = 63;
111   - else flignore = YES;
112   -
113   - if( ! flignore ) {
114   - short ctcharsinbuf = 3;
115   - BOOL flbreak = NO;
116   -
117   - if( flendtext ) {
118   - if( ! ixinbuf ) break;
119   - if( ( ixinbuf == 1 ) || ( ixinbuf == 2 ) ) ctcharsinbuf = 1;
120   - else ctcharsinbuf = 2;
121   - ixinbuf = 3;
122   - flbreak = YES;
123   - }
124   -
125   - inbuf [ixinbuf++] = ch;
126   -
127   - if( ixinbuf == 4 ) {
128   - ixinbuf = 0;
129   - outbuf [0] = ( inbuf[0] << 2 ) | ( ( inbuf[1] & 0x30) >> 4 );
130   - outbuf [1] = ( ( inbuf[1] & 0x0F ) << 4 ) | ( ( inbuf[2] & 0x3C ) >> 2 );
131   - outbuf [2] = ( ( inbuf[2] & 0x03 ) << 6 ) | ( inbuf[3] & 0x3F );
132   -
133   - for( i = 0; i < ctcharsinbuf; i++ )
134   - [mutableData appendBytes:&outbuf[i] length:1];
135   - }
136   -
137   - if( flbreak ) break;
138   - }
139   - }
140   - }
141   -
142   - self = [self initWithData:mutableData];
143   - return self;
144   -}
145   -
146   -#pragma mark -
147   -
148   -- (NSString *) base64Encoding {
149   - return [self base64EncodingWithLineLength:0];
150   -}
151   -
152   -- (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength {
153   - const unsigned char *bytes = [self bytes];
154   - NSMutableString *result = [NSMutableString stringWithCapacity:[self length]];
155   - unsigned long ixtext = 0;
156   - unsigned long lentext = [self length];
157   - long ctremaining = 0;
158   - unsigned char inbuf[3], outbuf[4];
159   - short i = 0;
160   - short charsonline = 0, ctcopy = 0;
161   - unsigned long ix = 0;
162   -
163   - while( YES ) {
164   - ctremaining = lentext - ixtext;
165   - if( ctremaining <= 0 ) break;
166   -
167   - for( i = 0; i < 3; i++ ) {
168   - ix = ixtext + i;
169   - if( ix < lentext ) inbuf[i] = bytes[ix];
170   - else inbuf [i] = 0;
171   - }
172   -
173   - outbuf [0] = (inbuf [0] & 0xFC) >> 2;
174   - outbuf [1] = ((inbuf [0] & 0x03) << 4) | ((inbuf [1] & 0xF0) >> 4);
175   - outbuf [2] = ((inbuf [1] & 0x0F) << 2) | ((inbuf [2] & 0xC0) >> 6);
176   - outbuf [3] = inbuf [2] & 0x3F;
177   - ctcopy = 4;
178   -
179   - switch( ctremaining ) {
180   - case 1:
181   - ctcopy = 2;
182   - break;
183   - case 2:
184   - ctcopy = 3;
185   - break;
186   - }
187   -
188   - for( i = 0; i < ctcopy; i++ )
189   - [result appendFormat:@"%c", encodingTable[outbuf[i]]];
190   -
191   - for( i = ctcopy; i < 4; i++ )
192   - [result appendFormat:@"%c",'='];
193   -
194   - ixtext += 3;
195   - charsonline += 4;
196   -
197   - if( lineLength > 0 ) {
198   - if (charsonline >= lineLength) {
199   - charsonline = 0;
200   - [result appendString:@"\n"];
201   - }
202   - }
203   - }
204   -
205   - return result;
206   -}
207   -
208   -
209   -
210   -// ================================================================================================
211   -// NSData+gzip.m
212   -// Drip
213   -//
214   -// Created by Nur Monson on 8/21/07.
215   -// Copyright 2007 theidiotproject. All rights reserved.
216   -//
217   -// FOUND HERE http://code.google.com/p/drop-osx/source/browse/trunk/Source/NSData%2Bgzip.m
218   -//
219   -// Also Check http://deusty.blogspot.com/2007/07/gzip-compressiondecompression.html
220   -// ================================================================================================
221   -
222   -#pragma mark -
223   -#pragma mark GZIP
224   -
225   -- (NSData *)gzipDeflate
226   -{
227   - if ([self length] == 0) return self;
228   -
229   - z_stream strm;
230   -
231   - strm.zalloc = Z_NULL;
232   - strm.zfree = Z_NULL;
233   - strm.opaque = Z_NULL;
234   - strm.total_out = 0;
235   - strm.next_in=(Bytef *)[self bytes];
236   - strm.avail_in = [self length];
237   -
238   - // Compresssion Levels:
239   - // Z_NO_COMPRESSION
240   - // Z_BEST_SPEED
241   - // Z_BEST_COMPRESSION
242   - // Z_DEFAULT_COMPRESSION
243   -
244   - if (deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, (15+16), 8, Z_DEFAULT_STRATEGY) != Z_OK) return nil;
245   -
246   - NSMutableData *compressed = [NSMutableData dataWithLength:16384]; // 16K chunks for expansion
247   -
248   - do {
249   -
250   - if (strm.total_out >= [compressed length])
251   - [compressed increaseLengthBy: 16384];
252   -
253   - strm.next_out = [compressed mutableBytes] + strm.total_out;
254   - strm.avail_out = [compressed length] - strm.total_out;
255   -
256   - deflate(&strm, Z_FINISH);
257   -
258   - } while (strm.avail_out == 0);
259   -
260   - deflateEnd(&strm);
261   -
262   - [compressed setLength: strm.total_out];
263   - return [NSData dataWithData:compressed];
264   -}
265   -
266   -- (NSData *)gzipInflate
267   -{
268   - if ([self length] == 0) return self;
269   -
270   - unsigned full_length = [self length];
271   - unsigned half_length = [self length] / 2;
272   -
273   - NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length];
274   - BOOL done = NO;
275   - int status;
276   -
277   - z_stream strm;
278   - strm.next_in = (Bytef *)[self bytes];
279   - strm.avail_in = [self length];
280   - strm.total_out = 0;
281   - strm.zalloc = Z_NULL;
282   - strm.zfree = Z_NULL;
283   -
284   - if (inflateInit2(&strm, (15+32)) != Z_OK) return nil;
285   - while (!done)
286   - {
287   - // Make sure we have enough room and reset the lengths.
288   - if (strm.total_out >= [decompressed length])
289   - [decompressed increaseLengthBy: half_length];
290   - strm.next_out = [decompressed mutableBytes] + strm.total_out;
291   - strm.avail_out = [decompressed length] - strm.total_out;
292   -
293   - // Inflate another chunk.
294   - status = inflate (&strm, Z_SYNC_FLUSH);
295   - if (status == Z_STREAM_END) done = YES;
296   - else if (status != Z_OK) break;
297   - }
298   - if (inflateEnd (&strm) != Z_OK) return nil;
299   -
300   - // Set real length.
301   - if (done)
302   - {
303   - [decompressed setLength: strm.total_out];
304   - return [NSData dataWithData: decompressed];
305   - }
306   - else return nil;
307   -}
308   -
309   -@end
310   -
15 RaptureXML/RXMLElement.h
@@ -29,26 +29,27 @@
29 29 //
30 30
31 31 #import <Foundation/Foundation.h>
32   -#import "TBXML.h"
  32 +#import <libxml2/libxml/xmlreader.h>
  33 +#import <libxml2/libxml/xmlmemory.h>
33 34
34 35 @interface RXMLElement : NSObject {
35   - TBXML *xml_;
36   - TBXMLElement *tbxmlElement_;
  36 + xmlDocPtr doc_;
  37 + xmlNodePtr node_;
37 38 }
38 39
39   -- (id)initFromXMLString:(NSString *)xmlString;
  40 +- (id)initFromXMLString:(NSString *)xmlString withEncoding:(NSStringEncoding)encoding;
40 41 - (id)initFromXMLFile:(NSString *)filename;
41 42 - (id)initFromXMLFile:(NSString *)filename fileExtension:(NSString*)extension;
42 43 - (id)initFromURL:(NSURL *)url;
43 44 - (id)initFromXMLData:(NSData *)data;
44   -- (id)initFromTBXMLElement:(TBXMLElement *)tbxmlElement;
  45 +- (id)initFromXMLNode:(xmlNodePtr)node;
45 46
46   -+ (id)elementFromXMLString:(NSString *)filename;
  47 ++ (id)elementFromXMLString:(NSString *)xmlString withEncoding:(NSStringEncoding)encoding;
47 48 + (id)elementFromXMLFile:(NSString *)filename;
48 49 + (id)elementFromXMLFilename:(NSString *)filename fileExtension:(NSString *)extension;
49 50 + (id)elementFromURL:(NSURL *)url;
50 51 + (id)elementFromXMLData:(NSData *)data;
51   -+ (id)elementFromTBXMLElement:(TBXMLElement *)tbxmlElement;
  52 ++ (id)elementFromXMLNode:(xmlNodePtr)node;
52 53
53 54 - (NSString *)attribute:(NSString *)attName;
54 55 - (NSInteger)attributeAsInt:(NSString *)attName;
205 RaptureXML/RXMLElement.m
@@ -32,10 +32,19 @@
32 32
33 33 @implementation RXMLElement
34 34
35   -- (id)initFromXMLString:(NSString *)xmlString {
  35 +- (id)initFromXMLString:(NSString *)xmlString withEncoding:(NSStringEncoding)encoding {
36 36 if ((self = [super init])) {
37   - xml_ = [[TBXML alloc] initWithXMLString:xmlString];
38   - tbxmlElement_ = xml_.rootXMLElement;
  37 + NSData *data = [xmlString dataUsingEncoding:encoding];
  38 +
  39 + doc_ = xmlReadMemory([data bytes], [data length], "", nil, XML_PARSE_RECOVER);
  40 +
  41 + if ([self isValid]) {
  42 + node_ = xmlDocGetRootElement(doc_);
  43 +
  44 + if (!node_) {
  45 + xmlFreeDoc(doc_); doc_ = nil;
  46 + }
  47 + }
39 48 }
40 49
41 50 return self;
@@ -43,17 +52,37 @@ - (id)initFromXMLString:(NSString *)xmlString {
43 52
44 53 - (id)initFromXMLFile:(NSString *)filename {
45 54 if ((self = [super init])) {
46   - xml_ = [[TBXML alloc] initWithXMLFile:filename];
47   - tbxmlElement_ = xml_.rootXMLElement;
  55 + NSString *fullPath = [[[NSBundle bundleForClass:self.class] bundlePath] stringByAppendingPathComponent:filename];
  56 + NSData *data = [NSData dataWithContentsOfFile:fullPath];
  57 +
  58 + doc_ = xmlReadMemory([data bytes], [data length], "", nil, XML_PARSE_RECOVER);
  59 +
  60 + if ([self isValid]) {
  61 + node_ = xmlDocGetRootElement(doc_);
  62 +
  63 + if (!node_) {
  64 + xmlFreeDoc(doc_); doc_ = nil;
  65 + }
  66 + }
48 67 }
49 68
50 69 return self;
51 70 }
52 71
53   -- (id)initFromXMLFile:(NSString *)filename fileExtension:(NSString*)extension {
  72 +- (id)initFromXMLFile:(NSString *)filename fileExtension:(NSString *)extension {
54 73 if ((self = [super init])) {
55   - xml_ = [[TBXML alloc] initWithXMLFile:filename fileExtension:extension];
56   - tbxmlElement_ = xml_.rootXMLElement;
  74 + NSString *fullPath = [[NSBundle bundleForClass:[self class]] pathForResource:filename ofType:extension];
  75 + NSData *data = [NSData dataWithContentsOfFile:fullPath];
  76 +
  77 + doc_ = xmlReadMemory([data bytes], [data length], "", nil, XML_PARSE_RECOVER);
  78 +
  79 + if ([self isValid]) {
  80 + node_ = xmlDocGetRootElement(doc_);
  81 +
  82 + if (!node_) {
  83 + xmlFreeDoc(doc_); doc_ = nil;
  84 + }
  85 + }
57 86 }
58 87
59 88 return self;
@@ -61,8 +90,17 @@ - (id)initFromXMLFile:(NSString *)filename fileExtension:(NSString*)extension {
61 90
62 91 - (id)initFromURL:(NSURL *)url {
63 92 if ((self = [super init])) {
64   - xml_ = [[TBXML alloc] initWithURL:url];
65   - tbxmlElement_ = xml_.rootXMLElement;
  93 + NSData *data = [NSData dataWithContentsOfURL:url];
  94 +
  95 + doc_ = xmlReadMemory([data bytes], [data length], "", nil, XML_PARSE_RECOVER);
  96 +
  97 + if ([self isValid]) {
  98 + node_ = xmlDocGetRootElement(doc_);
  99 +
  100 + if (!node_) {
  101 + xmlFreeDoc(doc_); doc_ = nil;
  102 + }
  103 + }
66 104 }
67 105
68 106 return self;
@@ -70,23 +108,31 @@ - (id)initFromURL:(NSURL *)url {
70 108
71 109 - (id)initFromXMLData:(NSData *)data {
72 110 if ((self = [super init])) {
73   - xml_ = [[TBXML alloc] initWithXMLData:data];
74   - tbxmlElement_ = xml_.rootXMLElement;
  111 + doc_ = xmlReadMemory([data bytes], [data length], "", nil, XML_PARSE_RECOVER);
  112 +
  113 + if ([self isValid]) {
  114 + node_ = xmlDocGetRootElement(doc_);
  115 +
  116 + if (!node_) {
  117 + xmlFreeDoc(doc_); doc_ = nil;
  118 + }
  119 + }
75 120 }
76 121
77 122 return self;
78 123 }
79 124
80   -- (id)initFromTBXMLElement:(TBXMLElement *)tbxmlElement {
  125 +- (id)initFromXMLNode:(xmlNodePtr)node {
81 126 if ((self = [super init])) {
82   - tbxmlElement_ = tbxmlElement;
  127 + doc_ = nil;
  128 + node_ = node;
83 129 }
84 130
85   - return self;
  131 + return self;
86 132 }
87 133
88   -+ (id)elementFromXMLString:(NSString *)filename {
89   - return [[[RXMLElement alloc] initFromXMLString:filename] autorelease];
  134 ++ (id)elementFromXMLString:(NSString *)attributeXML_ withEncoding:(NSStringEncoding)encoding {
  135 + return [[[RXMLElement alloc] initFromXMLString:attributeXML_ withEncoding:encoding] autorelease];
90 136 }
91 137
92 138 + (id)elementFromXMLFile:(NSString *)filename {
@@ -105,8 +151,8 @@ + (id)elementFromXMLData:(NSData *)data {
105 151 return [[[RXMLElement alloc] initFromXMLData:data] autorelease];
106 152 }
107 153
108   -+ (id)elementFromTBXMLElement:(TBXMLElement *)tbxmlElement {
109   - return [[[RXMLElement alloc] initFromTBXMLElement:tbxmlElement] autorelease];
  154 ++ (id)elementFromXMLNode:(xmlNodePtr)node {
  155 + return [[[RXMLElement alloc] initFromXMLNode:node] autorelease];
110 156 }
111 157
112 158 - (NSString *)description {
@@ -114,18 +160,23 @@ - (NSString *)description {
114 160 }
115 161
116 162 - (void)dealloc {
117   - [xml_ release];
  163 + if (doc_ != nil) xmlFreeDoc(doc_);
  164 +
118 165 [super dealloc];
119 166 }
120 167
121 168 #pragma mark -
122 169
123 170 - (NSString *)tag {
124   - return [TBXML elementName:tbxmlElement_];
  171 + return [NSString stringWithUTF8String:(const char *)node_->name];
125 172 }
126 173
127 174 - (NSString *)text {
128   - return [TBXML textForElement:tbxmlElement_];
  175 + xmlChar *key = xmlNodeGetContent(node_);
  176 + NSString *text = (key ? [NSString stringWithUTF8String:(const char *)key] : @"");
  177 + xmlFree(key);
  178 +
  179 + return text;
129 180 }
130 181
131 182 - (NSInteger)textAsInt {
@@ -137,7 +188,13 @@ - (double)textAsDouble {
137 188 }
138 189
139 190 - (NSString *)attribute:(NSString *)attName {
140   - return [TBXML valueOfAttributeNamed:attName forElement:tbxmlElement_];
  191 + const unsigned char *attCStr = xmlGetProp(node_, (const xmlChar *)[attName cStringUsingEncoding:NSUTF8StringEncoding]);
  192 +
  193 + if (attCStr) {
  194 + return [NSString stringWithUTF8String:(const char *)attCStr];
  195 + }
  196 +
  197 + return nil;
141 198 }
142 199
143 200 - (NSInteger)attributeAsInt:(NSString *)attName {
@@ -149,45 +206,60 @@ - (double)attributeAsDouble:(NSString *)attName {
149 206 }
150 207
151 208 - (BOOL)isValid {
152   - return (tbxmlElement_ != nil);
  209 + return (doc_ != nil);
153 210 }
154 211
155 212 #pragma mark -
156 213
157 214 - (RXMLElement *)child:(NSString *)tagName {
158 215 NSArray *components = [tagName componentsSeparatedByString:@"."];
159   - TBXMLElement *currTBXMLElement = tbxmlElement_;
  216 + xmlNodePtr cur = node_;
160 217
161 218 // navigate down
162 219 for (NSInteger i=0; i < components.count; ++i) {
163 220 NSString *iTagName = [components objectAtIndex:i];
164   -
  221 + const xmlChar *tagNameC = (const xmlChar *)[iTagName cStringUsingEncoding:NSUTF8StringEncoding];
  222 +
165 223 if ([iTagName isEqualToString:@"*"]) {
166   - currTBXMLElement = [TBXML childElementNamed:nil parentElement:currTBXMLElement];
  224 + cur = cur->children;
  225 +
  226 + while (cur != nil && cur->type != XML_ELEMENT_NODE) {
  227 + cur = cur->next;
  228 + }
167 229 } else {
168   - currTBXMLElement = [TBXML childElementNamed:iTagName parentElement:currTBXMLElement];
  230 + cur = cur->children;
  231 + while (cur != nil) {
  232 + if (cur->type == XML_ELEMENT_NODE && !xmlStrcmp(cur->name, tagNameC)) {
  233 + break;
  234 + }
  235 +
  236 + cur = cur->next;
  237 + }
169 238 }
170 239
171   - if (!currTBXMLElement) {
  240 + if (!cur) {
172 241 break;
173 242 }
174 243 }
175 244
176   - if (currTBXMLElement) {
177   - return [RXMLElement elementFromTBXMLElement:currTBXMLElement];
  245 + if (cur) {
  246 + return [RXMLElement elementFromXMLNode:cur];
178 247 }
179   -
  248 +
180 249 return nil;
181 250 }
182 251
183 252 - (NSArray *)children:(NSString *)tagName {
  253 + const xmlChar *tagNameC = (const xmlChar *)[tagName cStringUsingEncoding:NSUTF8StringEncoding];
184 254 NSMutableArray *children = [NSMutableArray array];
185   - TBXMLElement *currTBXMLElement = [TBXML childElementNamed:tagName parentElement:tbxmlElement_];
186   -
187   - if (currTBXMLElement) {
188   - do {
189   - [children addObject:[RXMLElement elementFromTBXMLElement:currTBXMLElement]];
190   - } while ((currTBXMLElement = [TBXML nextSiblingNamed:tagName searchFromElement:currTBXMLElement]));
  255 + xmlNodePtr cur = node_->children;
  256 +
  257 + while (cur != nil) {
  258 + if (cur->type == XML_ELEMENT_NODE && !xmlStrcmp(cur->name, tagNameC)) {
  259 + [children addObject:[RXMLElement elementFromXMLNode:cur]];
  260 + }
  261 +
  262 + cur = cur->next;
191 263 }
192 264
193 265 return [[children copy] autorelease];
@@ -197,46 +269,69 @@ - (NSArray *)children:(NSString *)tagName {
197 269
198 270 - (void)iterate:(NSString *)query with:(void (^)(RXMLElement *))blk {
199 271 NSArray *components = [query componentsSeparatedByString:@"."];
200   - TBXMLElement *currTBXMLElement = tbxmlElement_;
  272 + xmlNodePtr cur = node_;
201 273
202 274 // navigate down
203 275 for (NSInteger i=0; i < components.count; ++i) {
204 276 NSString *iTagName = [components objectAtIndex:i];
205 277
206 278 if ([iTagName isEqualToString:@"*"]) {
207   - currTBXMLElement = [TBXML childElementNamed:nil parentElement:currTBXMLElement];
  279 + cur = cur->children;
208 280
209 281 // different behavior depending on if this is the end of the query or midstream
210 282 if (i < (components.count - 1)) {
211 283 // midstream
212 284 do {
213   - RXMLElement *element = [RXMLElement elementFromTBXMLElement:currTBXMLElement];
214   - NSString *restOfQuery = [[components subarrayWithRange:NSMakeRange(i + 1, components.count - i - 1)] componentsJoinedByString:@"."];
215   - [element iterate:restOfQuery with:blk];
216   - } while ((currTBXMLElement = [TBXML nextSiblingNamed:nil searchFromElement:currTBXMLElement]));
  285 + if (cur->type == XML_ELEMENT_NODE) {
  286 + RXMLElement *element = [RXMLElement elementFromXMLNode:cur];
  287 + NSString *restOfQuery = [[components subarrayWithRange:NSMakeRange(i + 1, components.count - i - 1)] componentsJoinedByString:@"."];
  288 + [element iterate:restOfQuery with:blk];
  289 + }
  290 +
  291 + cur = cur->next;
  292 + } while (cur != nil);
217 293
218 294 }
219 295 } else {
220   - currTBXMLElement = [TBXML childElementNamed:iTagName parentElement:currTBXMLElement];
  296 + const xmlChar *tagNameC = (const xmlChar *)[iTagName cStringUsingEncoding:NSUTF8StringEncoding];
  297 +
  298 + cur = cur->children;
  299 + while (cur != nil) {
  300 + if (cur->type == XML_ELEMENT_NODE && !xmlStrcmp(cur->name, tagNameC)) {
  301 + break;
  302 + }
  303 +
  304 + cur = cur->next;
  305 + }
221 306 }
222 307
223   - if (!currTBXMLElement) {
  308 + if (!cur) {
224 309 break;
225 310 }
226 311 }
227   -
228   - if (currTBXMLElement) {
  312 +
  313 + if (cur) {
229 314 // enumerate
230 315 NSString *childTagName = [components lastObject];
231 316
232   - if ([childTagName isEqualToString:@"*"]) {
233   - childTagName = nil;
234   - }
235   -
236 317 do {
237   - RXMLElement *element = [RXMLElement elementFromTBXMLElement:currTBXMLElement];
238   - blk(element);
239   - } while ((currTBXMLElement = [TBXML nextSiblingNamed:childTagName searchFromElement:currTBXMLElement]));
  318 + if (cur->type == XML_ELEMENT_NODE) {
  319 + RXMLElement *element = [RXMLElement elementFromXMLNode:cur];
  320 + blk(element);
  321 + }
  322 +
  323 + if ([childTagName isEqualToString:@"*"]) {
  324 + cur = cur->next;
  325 + } else {
  326 + const xmlChar *tagNameC = (const xmlChar *)[childTagName cStringUsingEncoding:NSUTF8StringEncoding];
  327 +
  328 + while ((cur = cur->next)) {
  329 + if (cur->type == XML_ELEMENT_NODE && !xmlStrcmp(cur->name, tagNameC)) {
  330 + break;
  331 + }
  332 + }
  333 + }
  334 + } while (cur);
240 335 }
241 336 }
242 337
130 RaptureXML/TBXML.h
... ... @@ -1,130 +0,0 @@
1   -// ================================================================================================
2   -// TBXML.h
3   -// Fast processing of XML files
4   -//
5   -// ================================================================================================
6   -// Created by Tom Bradley on 21/10/2009.
7   -// Version 1.4
8   -//
9   -// Copyright (c) 2009 Tom Bradley
10   -//
11   -// Permission is hereby granted, free of charge, to any person obtaining a copy
12   -// of this software and associated documentation files (the "Software"), to deal
13   -// in the Software without restriction, including without limitation the rights
14   -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15   -// copies of the Software, and to permit persons to whom the Software is
16   -// furnished to do so, subject to the following conditions:
17   -//
18   -// The above copyright notice and this permission notice shall be included in
19   -// all copies or substantial portions of the Software.
20   -//
21   -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22   -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23   -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24   -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25   -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26   -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27   -// THE SOFTWARE.
28   -// ================================================================================================
29   -
30   -
31   -// ================================================================================================
32   -// Defines
33   -// ================================================================================================
34   -#define MAX_ELEMENTS 100
35   -#define MAX_ATTRIBUTES 100
36   -
37   -#define TBXML_ATTRIBUTE_NAME_START 0
38   -#define TBXML_ATTRIBUTE_NAME_END 1
39   -#define TBXML_ATTRIBUTE_VALUE_START 2
40   -#define TBXML_ATTRIBUTE_VALUE_END 3
41   -#define TBXML_ATTRIBUTE_CDATA_END 4
42   -
43   -// ================================================================================================
44   -// Structures
45   -// ================================================================================================
46   -typedef struct _TBXMLAttribute {
47   - char * name;
48   - char * value;
49   - struct _TBXMLAttribute * next;
50   -} TBXMLAttribute;
51   -
52   -typedef struct _TBXMLElement {
53   - char * name;
54   - char * text;
55   -
56   - TBXMLAttribute * firstAttribute;
57   -
58   - struct _TBXMLElement * parentElement;
59   -
60   - struct _TBXMLElement * firstChild;
61   - struct _TBXMLElement * currentChild;
62   -
63   - struct _TBXMLElement * nextSibling;
64   - struct _TBXMLElement * previousSibling;
65   -
66   -} TBXMLElement;
67   -
68   -typedef struct _TBXMLElementBuffer {
69   - TBXMLElement * elements;
70   - struct _TBXMLElementBuffer * next;
71   - struct _TBXMLElementBuffer * previous;
72   -} TBXMLElementBuffer;
73   -
74   -typedef struct _TBXMLAttributeBuffer {
75   - TBXMLAttribute * attributes;
76   - struct _TBXMLAttributeBuffer * next;
77   - struct _TBXMLAttributeBuffer * previous;
78   -} TBXMLAttributeBuffer;
79   -
80   -// ================================================================================================
81   -// TBXML Public Interface
82   -// ================================================================================================
83   -@interface TBXML : NSObject {
84   -
85   -@private
86   - TBXMLElement * rootXMLElement;
87   -
88   - TBXMLElementBuffer * currentElementBuffer;
89   - TBXMLAttributeBuffer * currentAttributeBuffer;
90   -
91   - long currentElement;
92   - long currentAttribute;
93   -
94   - char * bytes;
95   - long bytesLength;
96   -}
97   -
98   -@property (nonatomic, readonly) TBXMLElement * rootXMLElement;
99   -
100   -+ (id)tbxmlWithURL:(NSURL*)aURL;
101   -+ (id)tbxmlWithXMLString:(NSString*)aXMLString;
102   -+ (id)tbxmlWithXMLData:(NSData*)aData;
103   -+ (id)tbxmlWithXMLFile:(NSString*)aXMLFile;
104   -+ (id)tbxmlWithXMLFile:(NSString*)aXMLFile fileExtension:(NSString*)aFileExtension;
105   -
106   -- (id)initWithURL:(NSURL*)aURL;
107   -- (id)initWithXMLString:(NSString*)aXMLString;
108   -- (id)initWithXMLData:(NSData*)aData;
109   -- (id)initWithXMLFile:(NSString*)aXMLFile;
110   -- (id)initWithXMLFile:(NSString*)aXMLFile fileExtension:(NSString*)aFileExtension;
111   -
112   -@end
113   -
114   -// ================================================================================================
115   -// TBXML Static Functions Interface
116   -// ================================================================================================
117   -
118   -@interface TBXML (StaticFunctions)
119   -
120   -+ (NSString*) elementName:(TBXMLElement*)aXMLElement;
121   -+ (NSString*) textForElement:(TBXMLElement*)aXMLElement;
122   -+ (NSString*) valueOfAttributeNamed:(NSString *)aName forElement:(TBXMLElement*)aXMLElement;
123   -
124   -+ (NSString*) attributeName:(TBXMLAttribute*)aXMLAttribute;
125   -+ (NSString*) attributeValue:(TBXMLAttribute*)aXMLAttribute;
126   -
127   -+ (TBXMLElement*) nextSiblingNamed:(NSString*)aName searchFromElement:(TBXMLElement*)aXMLElement;
128   -+ (TBXMLElement*) childElementNamed:(NSString*)aName parentElement:(TBXMLElement*)aParentXMLElement;
129   -
130   -@end
599 RaptureXML/TBXML.m
... ... @@ -1,599 +0,0 @@
1   -// ================================================================================================
2   -// TBXML.m
3   -// Fast processing of XML files
4   -//
5   -// ================================================================================================
6   -// Created by Tom Bradley on 21/10/2009.
7   -// Version 1.4
8   -//