I am building a game engine and would like to implement my own parser for Collada files which is in XML format. I am trying to create a XMLParser to do this for me but for some reason when loading a .dae extension, nothing works.
Loading File Example:
//file = XMLParserDelegate
if let url = Bundle.main.url(forResource: colladaFileName, withExtension: "dae") {
if let parser = XMLParser.init(contentsOf: url) {
parser.delegate = self
parser.parse()
}
}
The funny thing is, all of this code gets executed. It isn't until it calls the function "parseErrorOccurred" that I can see the error message which states "Document is empty"
func parser(_ parser: XMLParser, parseErrorOccurred parseError: Error){
print(parseError) //result: Document is empty
}
HERE IS WHAT REALLY CONFUSES ME!
When I change the extension of my file to be .xml and change the function to be "withExtension: "xml"
the code compliles just fine, there are no errors and I can see all of the files data.
My goal is to not have to change my .dae file formats to .xml everysingle time. What can I do to fix this issue?
I managed to read the contents of a .dae
file by changing its type to Data
in Xcode as shown in this screenshot:
I don't know if this is a workaround that fits with your needs but I hope it helps