I am a beginner of xcode, have some experience of other program language.
Is NSXMLParser method impossible or not appreciated for parsing several xml file ?
I created two classes to parse several xml files.
parent class
class parent : NSObject {
var fileName:[String]! = ["aaa", "bbb", "ccc"]
var loadingNo = 0
func startLoading() { //1.start from this
let parser = loadXml( fileName: fileName[ loadingNo] , parent: self)//xml is parsed by subclass "loadXml"
}
func endParseXml() { // 5.parse ended and load next xml file
loadingNo++
if (loadingNo < fileName.count) { startLoading() }
}
}loadXml class
class loadXml : NSObject, NSXMLParserDelegate {
var p:parent!
init( fileName:String, parent:charaAssets ) {
super.init()
self.p = parent // 2.reference of parent
let url = NSBundle.mainBundle().URLForResource( fileName, withExtension: "xml")
let parser = NSXMLParser(contentsOfURL: url!)!
parser.delegate = self
parser.parse()
}
func parser(parser: NSXMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {
// 3. parse procedure here
}
func parserDidEndDocument(parser: NSXMLParser) {
p.endParseXml() //4.return to parent
}
}try to load next xml , then a error was shown.
'NSInternalInconsistencyException', reason: 'NSXMLParser does not support reentrant parsing.'
First I created one class to parse several xml, However the error occured, so separeted class but the error did not disappear.
I am not sure that the delegate should only one function in a program.
Or is it possible to next load xml without re-instantiation ?