Swift XMLParser refuses to parse xml file with 'plist' extension

120 views Asked by At

I have found a strange behavior when trying to parse a (xml-)plist file using XMLParser:
Parsing fails apparently just because of the 'plist'-extension – every other extension seems to work:

import Foundation

let plistURL = Bundle.main.url(forResource: "test", withExtension: "plist")! // valid xml-plist
let fooURL = Bundle.main.url(forResource: "test", withExtension: "foo")! // duplicate, renamed extension

let plistSuccess = XMLParser(contentsOf: plistURL)!.parse()   // false
let fooSuccess = XMLParser(contentsOf: fooURL)!.parse()       // true

Side note: The reason I am trying XMLParser instead of PropertyListSerialization or Codable is that the latter mess up ordering of dictionaries, which I need to maintain. (Parse a plist file with swift Codable using PropertyListDecoder and maintain sorting of dictionaries)

How can I make this work short of renaming the file?

0

There are 0 answers