I need to read data from the user. For convenience, the data will be in a property list, so it's easy to get a dictionary containing the property list data. But, since it's coming from outside, I need to validate that the data is in the required format, i.e. it has the right keys and the right sort of data for each key, e.g. <name>
has a string, <keys>
has an array of appropriate values.
Since this is part of a long-established product, and targets 10.13, I want to do this in Objective-C if possible. I've been working mostly with Swift in recent years, so I've forgotten a lot of what I used to know about Objective-C, I'm sure.
My first thought was to obtain the value for each key and check the class type with isa
, but I see that's deprecated in macOS 13 with no replacement. I don't see another way to check the class.
I'm sure other people have solved the same problem, but my searches have not turned up any answers.
libxml2 is available on all of our platforms at this time. You can use that for xml dtd validation. There is an example available among the libxml2 documentation (see http://www.xmlsoft.org/examples/#parse2.c for details). Note: xml dtd validation will validate the format of the xml based on the dtd. For validating the values stored in the xml, you'll need to read the xml and validate the values based on the keys yourself.