Skip to content

Commit 998d5c0

Browse files
authored
Update NSXML API to latest version (#547)
1 parent e074b8a commit 998d5c0

File tree

11 files changed

+208
-231
lines changed

11 files changed

+208
-231
lines changed

Foundation.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@
369369
EADE0BC91BD15E0000C49C64 /* NSXMLDTDNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = EADE0B8B1BD15DFF00C49C64 /* NSXMLDTDNode.swift */; };
370370
EADE0BCA1BD15E0000C49C64 /* NSXMLElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = EADE0B8C1BD15DFF00C49C64 /* NSXMLElement.swift */; };
371371
EADE0BCB1BD15E0000C49C64 /* NSXMLNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = EADE0B8D1BD15DFF00C49C64 /* NSXMLNode.swift */; };
372-
EADE0BCC1BD15E0000C49C64 /* NSXMLNodeOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EADE0B8E1BD15DFF00C49C64 /* NSXMLNodeOptions.swift */; };
373372
EADE0BCD1BD15E0000C49C64 /* NSXMLParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = EADE0B8F1BD15DFF00C49C64 /* NSXMLParser.swift */; };
374373
F03A43181D4877DD00A7791E /* CFAsmMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = F03A43161D48778200A7791E /* CFAsmMacros.h */; settings = {ATTRIBUTES = (Private, ); }; };
375374
F9E0BB371CA70B8000F7FF3C /* TestNSURLCredential.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9E0BB361CA70B8000F7FF3C /* TestNSURLCredential.swift */; };
@@ -805,7 +804,6 @@
805804
EADE0B8B1BD15DFF00C49C64 /* NSXMLDTDNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSXMLDTDNode.swift; sourceTree = "<group>"; };
806805
EADE0B8C1BD15DFF00C49C64 /* NSXMLElement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSXMLElement.swift; sourceTree = "<group>"; };
807806
EADE0B8D1BD15DFF00C49C64 /* NSXMLNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSXMLNode.swift; sourceTree = "<group>"; };
808-
EADE0B8E1BD15DFF00C49C64 /* NSXMLNodeOptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSXMLNodeOptions.swift; sourceTree = "<group>"; };
809807
EADE0B8F1BD15DFF00C49C64 /* NSXMLParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSXMLParser.swift; sourceTree = "<group>"; };
810808
F03A43161D48778200A7791E /* CFAsmMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFAsmMacros.h; sourceTree = "<group>"; };
811809
F9E0BB361CA70B8000F7FF3C /* TestNSURLCredential.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSURLCredential.swift; sourceTree = "<group>"; };
@@ -1435,7 +1433,6 @@
14351433
EADE0B8B1BD15DFF00C49C64 /* NSXMLDTDNode.swift */,
14361434
EADE0B8C1BD15DFF00C49C64 /* NSXMLElement.swift */,
14371435
EADE0B8D1BD15DFF00C49C64 /* NSXMLNode.swift */,
1438-
EADE0B8E1BD15DFF00C49C64 /* NSXMLNodeOptions.swift */,
14391436
EADE0B8F1BD15DFF00C49C64 /* NSXMLParser.swift */,
14401437
);
14411438
name = XML;
@@ -1972,7 +1969,6 @@
19721969
EADE0BC81BD15E0000C49C64 /* NSXMLDTD.swift in Sources */,
19731970
5B23AB8B1CE62F9B000DB898 /* PersonNameComponents.swift in Sources */,
19741971
EADE0BA61BD15E0000C49C64 /* NSMassFormatter.swift in Sources */,
1975-
EADE0BCC1BD15E0000C49C64 /* NSXMLNodeOptions.swift in Sources */,
19761972
5BECBA3A1D1CAE9A00B39B1F /* NSMeasurement.swift in Sources */,
19771973
5BF7AEB21BCD51F9008F214A /* NSNumber.swift in Sources */,
19781974
5BCD03821D3EE35C00E3FF9B /* TimeZone.swift in Sources */,

Foundation/NSXMLDTD.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ open class XMLDTD : XMLNode {
1818
return _CFXMLDTDPtr(_xmlNode)
1919
}
2020

21-
public convenience init(contentsOf url: URL, options mask: Int) throws {
21+
public init() {
22+
NSUnimplemented()
23+
}
24+
25+
public convenience init(contentsOf url: URL, options: Options = []) throws {
2226
let urlString = url.absoluteString
2327

2428
guard let node = _CFXMLParseDTD(urlString!) else {
@@ -28,7 +32,7 @@ open class XMLDTD : XMLNode {
2832
self.init(ptr: node)
2933
}
3034

31-
public convenience init(data: Data, options mask: Int) throws {
35+
public convenience init(data: Data, options: Options = []) throws {
3236
var unmanagedError: Unmanaged<CFError>? = nil
3337

3438
guard let node = _CFXMLParseDTDFromData(data._cfObject, &unmanagedError) else {
@@ -40,7 +44,7 @@ open class XMLDTD : XMLNode {
4044
}
4145

4246
self.init(ptr: node)
43-
} //primitive
47+
}
4448

4549
/*!
4650
@method openID

Foundation/NSXMLDTDNode.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ open class XMLDTDNode: XMLNode {
7575
@method initWithXMLString:
7676
@abstract Returns an element, attribute, entity, or notation DTD node based on the full XML string.
7777
*/
78-
public init?(XMLString string: String) {
78+
public init?(xmlString string: String) {
7979
guard let ptr = _CFXMLParseDTDNode(string) else { return nil }
8080
super.init(ptr: ptr)
8181
} //primitive
8282

83-
public override init(kind: XMLNode.Kind, options: Int) {
83+
public override init(kind: Kind, options: Options = []) {
8484
let ptr: _CFXMLNodePtr
8585

8686
switch kind {
@@ -93,10 +93,10 @@ open class XMLDTDNode: XMLNode {
9393
}
9494

9595
super.init(ptr: ptr)
96-
} //primitive
96+
}
9797

9898
/*!
99-
@method DTDKind
99+
@method dtdKind
100100
@abstract Sets the DTD sub kind.
101101
*/
102102
open var dtdKind: DTDKind {
@@ -184,13 +184,13 @@ open class XMLDTDNode: XMLNode {
184184
default:
185185
fatalError("This is not actually a DTD node!")
186186
}
187-
}//primitive
187+
}
188188

189189
/*!
190190
@method isExternal
191191
@abstract True if the system id is set. Valid for entities and notations.
192192
*/
193-
open var external: Bool {
193+
open var isExternal: Bool {
194194
return systemID != nil
195195
} //primitive
196196

Foundation/NSXMLDocument.swift

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,41 +59,46 @@ open class XMLDocument : XMLNode {
5959
private var _xmlDoc: _CFXMLDocPtr {
6060
return _CFXMLDocPtr(_xmlNode)
6161
}
62+
63+
public init() {
64+
NSUnimplemented()
65+
}
66+
6267
/*!
6368
@method initWithXMLString:options:error:
6469
@abstract Returns a document created from either XML or HTML, if the HTMLTidy option is set. Parse errors are returned in <tt>error</tt>.
6570
*/
66-
public convenience init(xmlString string: String, options mask: Int) throws {
71+
public convenience init(xmlString string: String, options: Options) throws {
6772
guard let data = string.data(using: .utf8) else {
6873
// TODO: Throw an error
6974
fatalError("String: '\(string)' could not be converted to NSData using UTF-8 encoding")
7075
}
7176

72-
try self.init(data: data, options: mask)
77+
try self.init(data: data, options: options)
7378
}
7479

7580
/*!
7681
@method initWithContentsOfURL:options:error:
7782
@abstract Returns a document created from the contents of an XML or HTML URL. Connection problems such as 404, parse errors are returned in <tt>error</tt>.
7883
*/
79-
public convenience init(contentsOf url: URL, options mask: Int) throws {
84+
public convenience init(contentsOf url: URL, options: Options) throws {
8085
let data = try Data(contentsOf: url, options: .dataReadingMappedIfSafe)
8186

82-
try self.init(data: data, options: mask)
87+
try self.init(data: data, options: options)
8388
}
8489

8590
/*!
8691
@method initWithData:options:error:
8792
@abstract Returns a document created from data. Parse errors are returned in <tt>error</tt>.
8893
*/
89-
public init(data: Data, options mask: Int) throws {
90-
let docPtr = _CFXMLDocPtrFromDataWithOptions(data._cfObject, Int32(mask))
94+
public init(data: Data, options: Options) throws {
95+
let docPtr = _CFXMLDocPtrFromDataWithOptions(data._cfObject, Int32(options.rawValue))
9196
super.init(ptr: _CFXMLNodePtr(docPtr))
9297

93-
if mask & NSXMLDocumentValidate != 0 {
98+
if options.contains(.documentValidate) {
9499
try validate()
95100
}
96-
} //primitive
101+
}
97102

98103
/*!
99104
@method initWithRootElement:
@@ -102,14 +107,16 @@ open class XMLDocument : XMLNode {
102107
public init(rootElement element: XMLElement?) {
103108
precondition(element?.parent == nil)
104109

105-
super.init(kind: .document, options: NSXMLNodeOptionsNone)
110+
super.init(kind: .document, options: [])
106111
if let element = element {
107112
_CFXMLDocSetRootElement(_xmlDoc, element._xmlNode)
108113
_childNodes.insert(element)
109114
}
110115
}
111116

112-
open class func replacementClassForClass(_ cls: AnyClass) -> AnyClass { NSUnimplemented() }
117+
open class func replacementClass(for cls: AnyClass) -> AnyClass {
118+
NSUnimplemented()
119+
}
113120

114121
/*!
115122
@method characterEncoding
@@ -126,7 +133,7 @@ open class XMLDocument : XMLNode {
126133
_CFXMLDocSetCharacterEncoding(_xmlDoc, nil)
127134
}
128135
}
129-
} //primitive
136+
}
130137

131138
/*!
132139
@method version
@@ -144,13 +151,13 @@ open class XMLDocument : XMLNode {
144151
_CFXMLDocSetVersion(_xmlDoc, nil)
145152
}
146153
}
147-
} //primitive
154+
}
148155

149156
/*!
150157
@method standalone
151158
@abstract Set whether this document depends on an external DTD. If this option is set the standalone declaration will appear on output.
152159
*/
153-
open var standalone: Bool {
160+
open var isStandalone: Bool {
154161
get {
155162
return _CFXMLDocStandalone(_xmlDoc)
156163
}
@@ -192,7 +199,7 @@ open class XMLDocument : XMLNode {
192199
@method MIMEType
193200
@abstract Set the MIME type, eg text/xml.
194201
*/
195-
open var mimeType: String? //primitive
202+
open var mimeType: String?
196203

197204
/*!
198205
@method DTD
@@ -250,15 +257,15 @@ open class XMLDocument : XMLNode {
250257
}
251258

252259
return XMLNode._objectNodeForNode(rootPtr) as? XMLElement
253-
} //primitive
260+
}
254261

255262
/*!
256263
@method insertChild:atIndex:
257264
@abstract Inserts a child at a particular index.
258265
*/
259266
open func insertChild(_ child: XMLNode, at index: Int) {
260267
_insertChild(child, atIndex: index)
261-
} //primitive
268+
}
262269

263270
/*!
264271
@method insertChildren:atIndex:
@@ -274,15 +281,15 @@ open class XMLDocument : XMLNode {
274281
*/
275282
open func removeChild(at index: Int) {
276283
_removeChildAtIndex(index)
277-
} //primitive
284+
}
278285

279286
/*!
280287
@method setChildren:
281288
@abstract Removes all existing children and replaces them with the new children. Set children to nil to simply remove all children.
282289
*/
283290
open func setChildren(_ children: [XMLNode]?) {
284291
_setChildren(children)
285-
} //primitive
292+
}
286293

287294
/*!
288295
@method addChild:
@@ -304,13 +311,13 @@ open class XMLDocument : XMLNode {
304311
@method XMLData
305312
@abstract Invokes XMLDataWithOptions with NSXMLNodeOptionsNone.
306313
*/
307-
/*@NSCopying*/ open var xmlData: Data { return xmlData(withOptions: NSXMLNodeOptionsNone) }
314+
/*@NSCopying*/ open var xmlData: Data { return xmlData(withOptions: []) }
308315

309316
/*!
310317
@method XMLDataWithOptions:
311318
@abstract The representation of this node as it would appear in an XML document, encoded based on characterEncoding.
312319
*/
313-
open func xmlData(withOptions options: Int) -> Data {
320+
open func xmlData(withOptions options: Options) -> Data {
314321
let string = xmlString(withOptions: options)
315322
// TODO: support encodings other than UTF-8
316323

@@ -321,19 +328,25 @@ open class XMLDocument : XMLNode {
321328
@method objectByApplyingXSLT:arguments:error:
322329
@abstract Applies XSLT with arguments (NSString key/value pairs) to this document, returning a new document.
323330
*/
324-
open func object(byApplyingXSLT xslt: NSData, arguments: [String : String]?) throws -> AnyObject { NSUnimplemented() }
331+
open func object(byApplyingXSLT xslt: Data, arguments: [String : String]?) throws -> Any {
332+
NSUnimplemented()
333+
}
325334

326335
/*!
327336
@method objectByApplyingXSLTString:arguments:error:
328337
@abstract Applies XSLT as expressed by a string with arguments (NSString key/value pairs) to this document, returning a new document.
329338
*/
330-
open func object(byApplyingXSLTString xslt: String, arguments: [String : String]?) throws -> AnyObject { NSUnimplemented() }
339+
open func object(byApplyingXSLTString xslt: String, arguments: [String : String]?) throws -> Any {
340+
NSUnimplemented()
341+
}
331342

332343
/*!
333344
@method objectByApplyingXSLTAtURL:arguments:error:
334345
@abstract Applies the XSLT at a URL with arguments (NSString key/value pairs) to this document, returning a new document. Error may contain a connection error from the URL.
335346
*/
336-
open func objectByApplyingXSLT(at xsltURL: URL, arguments argument: [String : String]?) throws -> AnyObject { NSUnimplemented() }
347+
open func objectByApplyingXSLT(at xsltURL: URL, arguments argument: [String : String]?) throws -> Any {
348+
NSUnimplemented()
349+
}
337350

338351
open func validate() throws {
339352
var unmanagedError: Unmanaged<CFError>? = nil

0 commit comments

Comments
 (0)