-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXMLInfo
More file actions
92 lines (70 loc) · 2.55 KB
/
XMLInfo
File metadata and controls
92 lines (70 loc) · 2.55 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import SWXMLHash
class XMLInfo : NSObject {
var statusCode : String = ""
required override init() {
super.init()
}
func parseXML(xml: String)throws ->Bool{
let xml = SWXMLHash.parse(xml)
let indexer = try xml.byKey("response")
let value = try indexer.byKey("statusCode")
statusCode = (value.element?.text)!
if check(statusCode) {
return false
}
try parseXML(indexer:indexer)
return true
}
func parseXML(indexer: XMLIndexer) throws{
let mirror = Mirror(reflecting: self)
for (_ , attr) in mirror.children.enumerated() {
if let propertyName = attr.label as String! {
let value = try indexer.byKey(propertyName)
if let xmlInfos = attr.value as? ParseXML {
print("--"+propertyName+"パーサー開始---" )
try xmlInfos.parseXML(indexer: value)
print("--"+propertyName+"パーサー終了---" )
}else{
let text = value.element?.text ?? ""
var keyValue : Any = text
if attr.value is Int {
if let intValue = Int(text) {
keyValue = intValue
}else{
throw IndexingError.key(key: propertyName)
}
}
self.setValue(keyValue, forKey: propertyName)
print(propertyName + " : " + text)
}
}
}
}
func check(_ statusCode: String?) -> Bool {
if statusCode == "000" {
return false
}
return true
}
}
protocol ParseXML {
func parseXML(indexer: XMLIndexer) throws;
}
class XMLInfos<T : XMLInfo> : NSObject, ParseXML {
var xmlInfos : [T] = [T]()
func parseXML(indexer: XMLIndexer) throws{
let childrens = indexer.children
for children in childrens {
print("childrenパーサー開始" )
let xmlInfo = T()
try xmlInfo.parseXML(indexer: children)
xmlInfos.append(xmlInfo)
}
}
}
class SampleInfo :XMLInfo {
var pointServiceCount : Int = 0
var pointServiceList : XMLInfos<PointInfo> = XMLInfos<PointInfo>()
var supportEventCount : Int = 0
var supportEventList : XMLInfos<PointInfo> = XMLInfos<PointInfo>()
}