-
Notifications
You must be signed in to change notification settings - Fork 104
/
XMLHeader.swift
53 lines (40 loc) · 1.23 KB
/
XMLHeader.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// XMLHeader.swift
// XMLCoder
//
// Created by Vincent Esche on 12/18/18.
//
import Foundation
public struct XMLHeader {
/// the XML standard that the produced document conforms to.
public let version: Double?
/// the encoding standard used to represent the characters in the produced document.
public let encoding: String?
/// indicates whether a document relies on information from an external source.
public let standalone: String?
public init(version: Double? = nil, encoding: String? = nil, standalone: String? = nil) {
self.version = version
self.encoding = encoding
self.standalone = standalone
}
func isEmpty() -> Bool {
return version == nil && encoding == nil && standalone == nil
}
func toXML() -> String? {
guard !isEmpty() else {
return nil
}
var string = "<?xml"
if let version = version {
string += " version=\"\(version)\""
}
if let encoding = encoding {
string += " encoding=\"\(encoding)\""
}
if let standalone = standalone {
string += " standalone=\"\(standalone)\""
}
string += "?>\n"
return string
}
}