@@ -59,41 +59,46 @@ open class XMLDocument : XMLNode {
59
59
private var _xmlDoc : _CFXMLDocPtr {
60
60
return _CFXMLDocPtr ( _xmlNode)
61
61
}
62
+
63
+ public init ( ) {
64
+ NSUnimplemented ( )
65
+ }
66
+
62
67
/*!
63
68
@method initWithXMLString:options:error:
64
69
@abstract Returns a document created from either XML or HTML, if the HTMLTidy option is set. Parse errors are returned in <tt>error</tt>.
65
70
*/
66
- public convenience init ( xmlString string: String , options mask : Int ) throws {
71
+ public convenience init ( xmlString string: String , options: Options ) throws {
67
72
guard let data = string. data ( using: . utf8) else {
68
73
// TODO: Throw an error
69
74
fatalError ( " String: ' \( string) ' could not be converted to NSData using UTF-8 encoding " )
70
75
}
71
76
72
- try self . init ( data: data, options: mask )
77
+ try self . init ( data: data, options: options )
73
78
}
74
79
75
80
/*!
76
81
@method initWithContentsOfURL:options:error:
77
82
@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>.
78
83
*/
79
- public convenience init ( contentsOf url: URL , options mask : Int ) throws {
84
+ public convenience init ( contentsOf url: URL , options: Options ) throws {
80
85
let data = try Data ( contentsOf: url, options: . dataReadingMappedIfSafe)
81
86
82
- try self . init ( data: data, options: mask )
87
+ try self . init ( data: data, options: options )
83
88
}
84
89
85
90
/*!
86
91
@method initWithData:options:error:
87
92
@abstract Returns a document created from data. Parse errors are returned in <tt>error</tt>.
88
93
*/
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 ) )
91
96
super. init ( ptr: _CFXMLNodePtr ( docPtr) )
92
97
93
- if mask & NSXMLDocumentValidate != 0 {
98
+ if options . contains ( . documentValidate ) {
94
99
try validate ( )
95
100
}
96
- } //primitive
101
+ }
97
102
98
103
/*!
99
104
@method initWithRootElement:
@@ -102,14 +107,16 @@ open class XMLDocument : XMLNode {
102
107
public init ( rootElement element: XMLElement ? ) {
103
108
precondition ( element? . parent == nil )
104
109
105
- super. init ( kind: . document, options: NSXMLNodeOptionsNone )
110
+ super. init ( kind: . document, options: [ ] )
106
111
if let element = element {
107
112
_CFXMLDocSetRootElement ( _xmlDoc, element. _xmlNode)
108
113
_childNodes. insert ( element)
109
114
}
110
115
}
111
116
112
- open class func replacementClassForClass( _ cls: AnyClass ) -> AnyClass { NSUnimplemented ( ) }
117
+ open class func replacementClass( for cls: AnyClass ) -> AnyClass {
118
+ NSUnimplemented ( )
119
+ }
113
120
114
121
/*!
115
122
@method characterEncoding
@@ -126,7 +133,7 @@ open class XMLDocument : XMLNode {
126
133
_CFXMLDocSetCharacterEncoding ( _xmlDoc, nil )
127
134
}
128
135
}
129
- } //primitive
136
+ }
130
137
131
138
/*!
132
139
@method version
@@ -144,13 +151,13 @@ open class XMLDocument : XMLNode {
144
151
_CFXMLDocSetVersion ( _xmlDoc, nil )
145
152
}
146
153
}
147
- } //primitive
154
+ }
148
155
149
156
/*!
150
157
@method standalone
151
158
@abstract Set whether this document depends on an external DTD. If this option is set the standalone declaration will appear on output.
152
159
*/
153
- open var standalone : Bool {
160
+ open var isStandalone : Bool {
154
161
get {
155
162
return _CFXMLDocStandalone ( _xmlDoc)
156
163
}
@@ -192,7 +199,7 @@ open class XMLDocument : XMLNode {
192
199
@method MIMEType
193
200
@abstract Set the MIME type, eg text/xml.
194
201
*/
195
- open var mimeType : String ? //primitive
202
+ open var mimeType : String ?
196
203
197
204
/*!
198
205
@method DTD
@@ -250,15 +257,15 @@ open class XMLDocument : XMLNode {
250
257
}
251
258
252
259
return XMLNode . _objectNodeForNode ( rootPtr) as? XMLElement
253
- } //primitive
260
+ }
254
261
255
262
/*!
256
263
@method insertChild:atIndex:
257
264
@abstract Inserts a child at a particular index.
258
265
*/
259
266
open func insertChild( _ child: XMLNode , at index: Int ) {
260
267
_insertChild ( child, atIndex: index)
261
- } //primitive
268
+ }
262
269
263
270
/*!
264
271
@method insertChildren:atIndex:
@@ -274,15 +281,15 @@ open class XMLDocument : XMLNode {
274
281
*/
275
282
open func removeChild( at index: Int ) {
276
283
_removeChildAtIndex ( index)
277
- } //primitive
284
+ }
278
285
279
286
/*!
280
287
@method setChildren:
281
288
@abstract Removes all existing children and replaces them with the new children. Set children to nil to simply remove all children.
282
289
*/
283
290
open func setChildren( _ children: [ XMLNode ] ? ) {
284
291
_setChildren ( children)
285
- } //primitive
292
+ }
286
293
287
294
/*!
288
295
@method addChild:
@@ -304,13 +311,13 @@ open class XMLDocument : XMLNode {
304
311
@method XMLData
305
312
@abstract Invokes XMLDataWithOptions with NSXMLNodeOptionsNone.
306
313
*/
307
- /*@NSCopying*/ open var xmlData : Data { return xmlData ( withOptions: NSXMLNodeOptionsNone ) }
314
+ /*@NSCopying*/ open var xmlData : Data { return xmlData ( withOptions: [ ] ) }
308
315
309
316
/*!
310
317
@method XMLDataWithOptions:
311
318
@abstract The representation of this node as it would appear in an XML document, encoded based on characterEncoding.
312
319
*/
313
- open func xmlData( withOptions options: Int ) -> Data {
320
+ open func xmlData( withOptions options: Options ) -> Data {
314
321
let string = xmlString ( withOptions: options)
315
322
// TODO: support encodings other than UTF-8
316
323
@@ -321,19 +328,25 @@ open class XMLDocument : XMLNode {
321
328
@method objectByApplyingXSLT:arguments:error:
322
329
@abstract Applies XSLT with arguments (NSString key/value pairs) to this document, returning a new document.
323
330
*/
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
+ }
325
334
326
335
/*!
327
336
@method objectByApplyingXSLTString:arguments:error:
328
337
@abstract Applies XSLT as expressed by a string with arguments (NSString key/value pairs) to this document, returning a new document.
329
338
*/
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
+ }
331
342
332
343
/*!
333
344
@method objectByApplyingXSLTAtURL:arguments:error:
334
345
@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.
335
346
*/
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
+ }
337
350
338
351
open func validate( ) throws {
339
352
var unmanagedError : Unmanaged < CFError > ? = nil
0 commit comments