I would like to parse student schedule only for the student "Karly". Task here means - classes. So I need to go to student-info first, and find out a student whose name is "Karly" and then parse task for her. Here's my XML:
<?xml version="1.0"?>
<students-scheule-information>
<student-schedule>
<student-info>
<name>Jiyoon Lee</name>
<phone>765-637-8532</phone>
<uniqueID>S201501</uniqueID>
</student-info>
<week-schedule>
<task>
<notificationID>notification1_1</notificationID>
<date>20151112</date>
<starttime>1200</starttime>
<endtime>1305</endtime>
<location>knoy376</location>
<title>Math</title>
<comments>good</comments>
<image>X</image>
<ischeckable>true</ischeckable>
<repeatnum>3</repeatnum>
<repeatinterval>5</repeatinterval>
</task>
<task>
<notificationID>notification1_2</notificationID>
<date>20151111</date>
<starttime>1200</starttime>
<endtime>1305</endtime>
<location>knoy376</location>
<title>History</title>
<comments>good</comments>
<image>X</image>
<ischeckable>true</ischeckable>
<repeatnum>3</repeatnum>
<repeatinterval>5</repeatinterval>
</task>
<task>
<notificationID>notification1_3</notificationID>
<date>20151113</date>
<starttime>0930</starttime>
<endtime>1200</endtime>
<location>knoy376</location>
<title>Geography</title>
<comments>good</comments>
<image>X</image>
<ischeckable>true</ischeckable>
<repeatnum>3</repeatnum>
<repeatinterval>5</repeatinterval>
</task>
<task>
<notificationID>notification1_4</notificationID>
<date>20151109</date>
<starttime>1200</starttime>
<endtime>1735</endtime>
<location>knoy376</location>
<title>Art</title>
<comments>good</comments>
<image>X</image>
<ischeckable>true</ischeckable>
<repeatnum>3</repeatnum>
<repeatinterval>5</repeatinterval>
</task>
<task>
<notificationID>notification1_5</notificationID>
<date>20151109</date>
<starttime>2000</starttime>
<endtime>2100</endtime>
<location>knoy376</location>
<title>Intermediate German</title>
<comments>good</comments>
<image>X</image>
<ischeckable>true</ischeckable>
<repeatnum>3</repeatnum>
<repeatinterval>5</repeatinterval>
</task>
</week-schedule>
</student-schedule>
<student-schedule>
<student-info>
<name>Karly</name>
<phone>765-637-8222</phone>
<uniqueID>S201502</uniqueID>
</student-info>
<week-schedule>
<task>
<notificationID>notification3</notificationID>
<date>20151109</date>
<starttime>2210</starttime>
<endtime>2305</endtime>
<location>knoy376</location>
<title>Chemisrty</title>
<comments>Cool</comments>
<image>X</image>
<ischeckable>true</ischeckable>
<repeatnum>3</repeatnum>
<repeatinterval>5</repeatinterval>
</task>
<task>
<notificationID>notification1_5</notificationID>
<date>20151109</date>
<starttime>2000</starttime>
<endtime>2100</endtime>
<location>knoy376</location>
<title>History</title>
<comments>good</comments>
<image>X</image>
<ischeckable>true</ischeckable>
<repeatnum>3</repeatnum>
<repeatinterval>5</repeatinterval>
</task>
<task>
<notificationID>notification1_5</notificationID>
<date>20151112</date>
<starttime>2000</starttime>
<endtime>2100</endtime>
<location>knoy376</location>
<title>Math</title>
<comments>good</comments>
<image>X</image>
<ischeckable>true</ischeckable>
<repeatnum>3</repeatnum>
<repeatinterval>5</repeatinterval>
</task>
<task>
<notificationID>notification1_5</notificationID>
<date>20151111</date>
<starttime>1130</starttime>
<endtime>1420</endtime>
<location>knoy376</location>
<title>Biology</title>
<comments>good</comments>
<image>X</image>
<ischeckable>true</ischeckable>
<repeatnum>3</repeatnum>
<repeatinterval>5</repeatinterval>
</task>
<task>
<notificationID>notification1_5</notificationID>
<date>20151113</date>
<starttime>1000</starttime>
<endtime>1300</endtime>
<location>knoy376</location>
<title>Geography</title>
<comments>good</comments>
<image>X</image>
<ischeckable>true</ischeckable>
<repeatnum>3</repeatnum>
<repeatinterval>5</repeatinterval>
</task>
</week-schedule>
</student-schedule>
</students-scheule-information>
I also have this code here for NSXMLParser which shows all for both students:
func parser(parser: NSXMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {
anElement = elementName
if elementName == "task" {
title = String()
}
}
func parser(parser: NSXMLParser, foundCharacters string: String) {
let data = string.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
if (!data.isEmpty) {
switch anElement {
case "title":
aTitle = data
case "starttime":
aStartTime = data
case "endtime":
anEndTime = data
case "location":
aLocation = data
default:
print("Check your file")
}
}
}
func parser(parser: NSXMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
if elementName == "task" {
let oneClass: TheClass = TheClass()
oneClass.title = aTitle
oneClass.location = aLocation
oneClass.startTime = aStartTime
oneClass.endTime = anEndTime
oneClass.classColor = aClassColor
classList.append(oneClass)
}
}
Thanks a lot!!!